home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / clisp-li.000 / clisp-li / clisp-1996-07-22 / doc / impnotes.txt < prev    next >
Encoding:
Text File  |  1996-07-22  |  101.4 KB  |  2,817 lines

  1.                 Implementation Notes for CLISP
  2.                 ==============================
  3.                 Last modified: 21 July 1996.
  4.  
  5. This implementation is mostly compatible to the standard reference
  6.  
  7.        Guy L. Steele Jr.: Common Lisp - The Language (1st ed.).
  8.        Digital Press 1984, 465 pages.
  9.        ("CLtL1" for short)
  10.  
  11. and to the older parts of
  12.  
  13.        Guy L. Steele Jr.: Common Lisp - The Language (2nd ed.).
  14.        Digital Press 1990, 1032 pages.
  15.        ("CLtL2" for short)
  16.  
  17.  
  18. These notes document the differences of the CLISP implementation of Common
  19. Lisp to the standard CLtL1, and some implementation details.
  20.  
  21. The differences between CLtL1 and CLtL2 are made up of X3J13 votes. CLISP's
  22. position with respect to these votes is listed in cltl2.txt.
  23.  
  24.  
  25.                       CHAPTER 1: Introduction
  26.                       -----------------------
  27.  
  28. No notes.
  29.  
  30.  
  31.                        CHAPTER 2: Data Types
  32.                        ---------------------
  33.  
  34. All the data types are implemented: numbers, characters, symbols, lists,
  35. arrays, hash tables, readtables, packages, pathnames, streams, random
  36. states, structures and functions.
  37.  
  38. 2.1.3.
  39. ------
  40.  
  41. There are four floating point types: short-float, single-float, double-float
  42. and long-float:
  43.                   sign    mantissa   exponent
  44.    short-float    1 bit   16+1 bits   8 bits
  45.    single-float   1 bit   23+1 bits   8 bits   CLISP uses IEEE format
  46.    double-float   1 bit   52+1 bits  11 bits   CLISP uses IEEE format
  47.    long-float     1 bit   >=64 bits  32 bits
  48.  
  49. The single and double float formats are those of the IEEE standard (1981),
  50. except that CLISP does not support features like +0, -0, +inf, -inf, gradual
  51. underflow, NaN, etc. (Common Lisp does not make use of these features.)
  52.  
  53. Long floats have variable mantissa length, which is a multiple of 16 (or 32,
  54. depending on the word size of the processor). The default length used when
  55. long floats are read is given by the place (LONG-FLOAT-DIGITS). It can be
  56. set by (SETF (LONG-FLOAT-DIGITS) nnn), where nnn is a positive integer.
  57.  
  58. 2.1.4.
  59. ------
  60.  
  61. Complex numbers can have a real part and an imaginary part of different
  62. types. For example, (SQRT -9.0) evaluates to the number #C(0 3.0), which has
  63. a real part of exactly 0, not only 0.0 (which would mean "approximately 0").
  64. The type specifier for this is (COMPLEX INTEGER SINGLE-FLOAT), and
  65.  
  66.            (COMPLEX type-of-real-part type-of-imaginary-part)
  67.  
  68. in general.
  69. The type specifier (COMPLEX type) is equivalent to (COMPLEX type type).
  70.  
  71. 2.2.1.
  72. ------
  73.  
  74. The characters are ordered according to the ASCII encoding.
  75.  
  76. More precisely, CLISP uses the ISO Latin-1 (ISO 8859-1) character set:
  77.              $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $A $B $C $D $E $F
  78.          $00 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  79.          $10 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  80.          $20     !  "  #  $  %  &  '  (  )  *  +  ,  -  .  /
  81.          $30  0  1  2  3  4  5  6  7  8  9  :  ;  <  =  >  ?
  82.          $40  @  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O
  83.          $50  P  Q  R  S  T  U  V  W  X  Y  Z  [  \  ]  ^  _
  84.          $60  `  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o
  85.          $70  p  q  r  s  t  u  v  w  x  y  z  {  |  }  ~   
  86.          $80                                                
  87.          $90                                                
  88.          $A0  á  í  ó  ú  ñ  Ñ  ª  º  ¿  ⌐  ¬  ½  ¼  ¡  «  »
  89.          $B0  ░  ▒  ▓  │  ┤  ╡  ╢  ╖  ╕  ╣  ║  ╗  ╝  ╜  ╛  ┐
  90.          $C0  └  ┴  ┬  ├  ─  ┼  ╞  ╟  ╚  ╔  ╩  ╦  ╠  ═  ╬  ╧
  91.          $D0  ╨  ╤  ╥  ╙  ╘  ╒  ╓  ╫  ╪  ┘  ┌  █  ▄  ▌  ▐  ▀
  92.          $E0  α  ß  Γ  π  Σ  σ  µ  τ  Φ  Θ  Ω  δ  ∞  φ  ε  ∩
  93.          $F0  ≡  ±  ≥  ≤  ⌠  ⌡  ÷  ≈  °  ∙  ·  √  ⁿ  ²  ■   
  94. Here ** are control characters, not graphic characters. (The characters left
  95. blank here cannot be represented in this character set).
  96.  
  97. The following are standard characters:
  98.   #\Space               $20
  99.   #\Newline             $0A
  100. The following are semi-standard characters:
  101.   #\Backspace           $08
  102.   #\Tab                 $09
  103.   #\Linefeed            $0A
  104.   #\Page                $0C
  105.   #\Return              $0D
  106.   #\Rubout              $7F
  107.  
  108. 2.2.2.
  109. ------
  110.  
  111. #\Newline is the delimiter between lines.
  112.  
  113. When reading from a file, CR/LF is converted to #\Newline, and CR not
  114. followed by LF is read as #\Return.
  115.  
  116. 2.2.3.
  117. ------
  118.  
  119. There are the following additional characters with names:
  120.   #\Null                $00
  121.   #\Bell                $07
  122.   #\Escape              $1B
  123.  
  124. 2.2.4.
  125. ------
  126.  
  127. The code of a character is >=0, <256. CHAR-CODE-LIMIT = 256.
  128.  
  129. There are fonts 0 to 15, and CHAR-FONT-LIMIT = 16. But the system itself
  130. uses only font 0.
  131.  
  132. The following bits attributes are implemented: :CONTROL, :META, :SUPER,
  133. :HYPER. Therefore CHAR-BITS-LIMIT = 16.
  134. The system itself uses these bits only to mention special keys and
  135. Control/Alternate/Shift key status on return from
  136. (READ-CHAR *KEYBOARD-INPUT*).
  137.  
  138. 2.5.
  139. ----
  140.  
  141. The maximum rank (number of dimensions) of an array is 65535 on 16-bit
  142. processors, 4294967295 on 32-bit processors.
  143.  
  144. 2.10.
  145. -----
  146.  
  147. The CLtL2 types BROADCAST-STREAM, CONCATENATED-STREAM, ECHO-STREAM,
  148. SYNONYM-STREAM, STRING-STREAM, FILE-STREAM, TWO-WAY-STREAM are implemented.
  149.  
  150. 2.13.
  151. -----
  152.  
  153. All the functions built by FUNCTION, COMPILE and the like are atoms. There
  154. are built-in functions written in C, compiled functions (both of type
  155. COMPILED-FUNCTION) and interpreted functions (of type FUNCTION).
  156. The possible function names (CLtL1 p. 59) are symbols and lambda expressions.
  157.  
  158. 2.14.
  159. -----
  160.  
  161. This is the list of objects whose external representation can not be
  162. meaningfully read in:
  163.   * all structures lacking a keyword constructor.
  164.   * all arrays except strings, if *PRINT-ARRAY* = NIL.
  165.   * #<SYSTEM-FUNCTION name>     built-in function written in C
  166.   * #<ADD-ON-SYSTEM-FUNCTION name>  other function written in C
  167.   * #<SPECIAL-FORM name>        special form handler
  168.   * #<COMPILED-CLOSURE name>    compiled function, if *PRINT-CLOSURE* = NIL
  169.   * #<CLOSURE name ...>         interpreted function
  170.   * #<FRAME-POINTER #x...>      pointer to a stack frame
  171.   * #<DISABLED POINTER>         frame pointer which has become invalid on
  172.                                 exit from the corresponding BLOCK or TAGBODY
  173.   * #<...-STREAM ...>           stream
  174.   * #<PACKAGE name>             package
  175.   * #<HASH-TABLE #x...>         hash table, if *PRINT-ARRAY* = NIL
  176.   * #<READTABLE #x...>          readtable
  177.   * #<SYMBOL-MACRO form>        symbol-macro handler
  178.   * #<FOREIGN-POINTER #x...>    foreign pointer
  179.   * #<FOREIGN-ADDRESS #x...>        foreign address
  180.   * #<FOREIGN-VARIABLE name #x...>  foreign variable
  181.   * #<FOREIGN-FUNCTION name #x...>  foreign function
  182.   * #<UNBOUND>                  "value" of a symbol without value, "value"
  183.                                 of an unsupplied optional or keyword argument
  184.   * #<SPECIAL REFERENCE>        environment marker for variables declared
  185.                                 SPECIAL
  186.   * #<DOT>                      internal READ result for "."
  187.   * #<END OF FILE>              internal READ result, when the end of file
  188.                                 is reached
  189.   * #<READ-LABEL ...>           intermediate READ result for #n#
  190.   * #<ADDRESS #x...>            machine address, should not occur
  191.   * #<SYSTEM-POINTER #x...>     should not occur
  192.  
  193. 2.15.
  194. -----
  195.  
  196. The type NUMBER is the disjoint union of the types REAL and COMPLEX. (CLtL
  197. wording: "exhaustive partition")
  198. The type REAL is the disjoint union of the types RATIONAL and FLOAT.
  199. The type RATIONAL is the disjoint union of the types INTEGER and RATIO.
  200. The type INTEGER is the disjoint union of the types FIXNUM and BIGNUM.
  201. The type FLOAT is the disjoint union of the types SHORT-FLOAT, SINGLE-FLOAT,
  202. DOUBLE-FLOAT and LONG-FLOAT.
  203.  
  204.  
  205.                      CHAPTER 3: Scope and Extent
  206.                      ---------------------------
  207.  
  208. is implemented as described.
  209.  
  210.  
  211.                       CHAPTER 4: Type Specifiers
  212.                       --------------------------
  213.  
  214. 4.4.
  215. ----
  216.  
  217. The CLtL2 type specifier (EQL object) denotes the singleton set {object}.
  218.  
  219. 4.5.
  220. ----
  221.  
  222. The general form of the COMPLEX type specifier is
  223. (COMPLEX type-of-real-part type-of-imaginary-part).
  224. The type specifier (COMPLEX type) is equivalent to (COMPLEX type type).
  225.  
  226. 4.6.
  227. ----
  228.  
  229. The CLtL2 type specifier (REAL low high) denotes the real numbers between low
  230. and high.
  231.  
  232. 4.7.
  233. ----
  234.  
  235. DEFTYPE lambda lists are subject to destructuring (nested lambda lists are
  236. allowed, as in DEFMACRO) and may contain a &WHOLE marker, but no
  237. &ENVIRONMENT marker.
  238.  
  239. 4.9.
  240. ----
  241.  
  242. The possible results of TYPE-OF are:
  243.  CONS
  244.  SYMBOL NULL
  245.  FIXNUM BIGNUM RATIO SHORT-FLOAT SINGLE-FLOAT DOUBLE-FLOAT LONG-FLOAT COMPLEX
  246.  CHARACTER
  247.  (ARRAY element-type dimensions), (SIMPLE-ARRAY element-type dimensions)
  248.  (VECTOR T size), (SIMPLE-VECTOR size)
  249.  (STRING size), (SIMPLE-STRING size)
  250.  (BIT-VECTOR size), (SIMPLE-BIT-VECTOR size)
  251.  FUNCTION COMPILED-FUNCTION
  252.  STREAM FILE-STREAM SYNONYM-STREAM BROADCAST-STREAM CONCATENATED-STREAM
  253.  TWO-WAY-STREAM ECHO-STREAM STRING-STREAM
  254.  PACKAGE HASH-TABLE READTABLE PATHNAME LOGICAL-PATHNAME RANDOM-STATE BYTE
  255.  LOAD-TIME-EVAL SYMBOL-MACRO FOREIGN-VARIABLE FOREIGN-FUNCTION READ-LABEL
  256.  FRAME-POINTER SYSTEM-INTERNAL
  257.  ADDRESS (should not occur)
  258.  any other symbol (structure types or CLOS classes)
  259.  a class (CLOS classes without proper name)
  260.  
  261.  
  262.                        CHAPTER 5: Program Structure
  263.                        ----------------------------
  264.  
  265. 5.1.3.
  266. ------
  267.  
  268. In addition to the 24 special forms listed on p. 57 (CLtL2: p. 73), the
  269. CLtL2 special forms LOCALLY, SYMBOL-MACROLET, LOAD-TIME-VALUE are implemented,
  270. and the macros
  271. PSETQ, PROG1, PROG2, WHEN, UNLESS, COND, MULTIPLE-VALUE-LIST,
  272. MULTIPLE-VALUE-BIND, MULTIPLE-VALUE-SETQ, AND, OR
  273. are implemented as special forms.
  274.  
  275. Constants may not be bound dynamically or lexically.
  276.  
  277. 5.2.2.
  278. ------
  279.  
  280. LAMBDA-LIST-KEYWORDS =
  281.     (&OPTIONAL &REST &KEY &ALLOW-OTHER-KEYS &AUX &BODY &WHOLE &ENVIRONMENT)
  282.  
  283. LAMBDA-PARAMETERS-LIMIT is 65536 on 16-bit processors, 4294967296 on 32-bit
  284. processors.
  285.  
  286. 5.3.
  287. ----
  288.  
  289. DEFUN and DEFMACRO are allowed in non-toplevel positions.
  290. As an example, consider the old (CLtL1) definition of GENSYM:
  291. (let ((gensym-prefix "G")
  292.       (gensym-count 1))
  293.   (defun gensym (&optional (x nil s))
  294.     (when s
  295.       (cond ((stringp x) (setq gensym-prefix x))
  296.             ((integerp x)
  297.              (if (minusp x)
  298.                (error "~S: index ~S is negative" 'gensym x)
  299.                (setq gensym-count x)
  300.             ))
  301.             (t (error "~S: argument ~S of wrong type" 'gensym x))
  302.     ) )
  303.     (prog1
  304.       (make-symbol
  305.         (concatenate 'string
  306.           gensym-prefix
  307.           (write-to-string gensym-count :base 10 :radix nil)
  308.       ) )
  309.       (incf gensym-count)
  310. ) )
  311.  
  312. 5.3.2.
  313. ------
  314.  
  315. (PROCLAIM '(SPECIAL var)) declarations may not be undone. The same holds
  316. for DEFVAR, DEFPARAMETER and DEFCONSTANT declarations.
  317.  
  318. It is an error if a DEFCONSTANT variable is bound at the moment the
  319. DEFCONSTANT is executed, but DEFCONSTANT does not check this.
  320.  
  321. Constants may not be bound dynamically or lexically.
  322.  
  323. 5.3.3.
  324. ------
  325.  
  326. EVAL-WHEN also accepts the situations (NOT EVAL) and (NOT COMPILE).
  327.  
  328.  
  329.                       CHAPTER 6: Predicates
  330.                       ---------------------
  331.  
  332. 6.2.2.
  333. ------
  334.  
  335. REALP returns T is its argument is a real number, NIL otherwise.
  336.  
  337. COMPILED-FUNCTION-P returns T on built-in functions written in C, compiled
  338. functions and special form handlers. Therefore COMPILED-FUNCTION is not a
  339. subtype of FUNCTION.
  340.  
  341. 6.3.
  342. ----
  343.  
  344. EQ compares characters and fixnums as EQL does. No unnecessary copies are
  345. made of characters and numbers. Nevertheless, one should use EQL.
  346.  
  347. (let ((x y)) (eq x x)) always returns T, regardless of y.
  348.  
  349. 6.4.
  350. ----
  351.  
  352. AND and OR are implemented as special forms and, as such, rather efficient.
  353.  
  354.  
  355.                       CHAPTER 7: Control Structure
  356.                       ----------------------------
  357.  
  358. 7.1.1.
  359. ------
  360.  
  361. (FUNCTION symbol) returns the local function definition established by FLET
  362. or LABELS, if it exists, otherwise the global function definition.
  363.  
  364. The CLtL2 place (FDEFINITION function-name) is implemented.
  365.  
  366. (SPECIAL-FORM-P symbol) returns NIL or T. If it returns T, then
  367. (SYMBOL-FUNCTION symbol) returns the (useless) special form handler.
  368.  
  369. 7.1.2.
  370. ------
  371.  
  372. PSETQ is implemented as a special form and, as such, rather efficient.
  373.  
  374. 7.2.
  375. ----
  376.  
  377. (SETF (SYMBOL-FUNCTION symbol) object) requires object to be either a
  378. function, a SYMBOL-FUNCTION return value or a lambda expression. A lambda
  379. expression is thereby immediately converted to a function.
  380.  
  381. SETF also accepts places yielding multiple values.
  382.  
  383. Additional places:
  384.  
  385. * FUNCALL:
  386.   (SETF (FUNCALL #'symbol ...) object) and
  387.   (SETF (FUNCALL 'symbol ...) object)
  388.   are equivalent to (SETF (symbol ...) object).
  389.  
  390. * GET-DISPATCH-MACRO-CHARACTER:
  391.   (SETF (GET-DISPATCH-MACRO-CHARACTER ...) ...)
  392.   performs a SET-DISPATCH-MACRO-CHARACTER.
  393.  
  394. * LONG-FLOAT-DIGITS:
  395.   (SETF (LONG-FLOAT-DIGITS) digits) sets the default mantissa length of long
  396.   floats to digits bits.
  397.  
  398. * VALUES:
  399.   (SETF (VALUES place1 ... placek) form)
  400.   is approximately equivalent to
  401.      (MULTIPLE-VALUE-BIND (dummy1 ... dummyk) form
  402.        (SETF place1 dummy1 ... placek dummyk)
  403.        (VALUES dummy1 ... dummyk)
  404.      )
  405.   Example:
  406.     (SETF (VALUES A B) (VALUES B A)) interchanges the values of A and B.
  407.  
  408. * VALUES-LIST:
  409.   (SETF (VALUES-LIST list) form)  is equivalent to
  410.   (VALUES-LIST (SETF list (MULTIPLE-VALUE-LIST form)))
  411.  
  412. &KEY markers in DEFSETF lambda lists are supported, but the corresponding
  413. keywords must appear literally in the program text.
  414.  
  415. (GET-SETF-METHOD form &optional env) and
  416. (GET-SETF-METHOD-MULTIPLE-VALUE form &optional env)
  417. receives as optional argument the environment necessary for macro expansions.
  418. In DEFINE-SETF-METHOD lambda lists, one can specify &ENVIRONMENT and a
  419. variable, which will be bound to the environment. This environment should be
  420. passed to all calls of GET-SETF-METHOD and GET-SETF-METHOD-MULTIPLE-VALUE.
  421. If this is done, even local macros will be interpreted as places correctly.
  422.  
  423. 7.3.
  424. ----
  425.  
  426. CALL-ARGUMENTS-LIMIT is 65536 on 16-bit processors, 4294967296 on 32-bit
  427. processors.
  428.  
  429. 7.4.
  430. ----
  431.  
  432. PROG1 and PROG2 are implemented as special forms and, as such, rather
  433. efficient.
  434.  
  435. 7.5.
  436. ----
  437.  
  438. The CLtL2 special form SYMBOL-MACROLET is implemented.
  439.  
  440. The macro DEFINE-SYMBOL-MACRO establishes symbol macros with global scope
  441. (as opposed to symbol macros defined with SYMBOL-MACROLET, which have local
  442. scope): (DEFINE-SYMBOL-MACRO symbol expansion).
  443. The function SYMBOL-MACRO-EXPAND tests for a symbol macro: If symbol is
  444. defined as symbol macro, (SYMBOL-MACRO-EXPAND symbol) returns two values,
  445. T and the expansion, else it returns NIL.
  446. Calling BOUNDP on a symbol defined as symbol macro returns T.
  447. Calling SYMBOL-VALUE on a symbol defined as symbol macro returns the value
  448. of the expansion. Calling SET on a symbol defined as symbol macro calls
  449. SETF on the expansion.
  450. Calling MAKUNBOUND on a symbol defined as symbol macro removes the symbol
  451. macro definition.
  452.  
  453. If using the optional package MACROS3:
  454.   The macros LETF and LETF* are like LET and LET*, resp., except that they
  455.   can bind places, even places with multiple values.
  456.   Example:
  457.   (LETF (((VALUES A B) form)) ...)
  458.     is equivalent to
  459.     (MULTIPLE-VALUE-BIND (A B) form ...)
  460.   (LETF (((FIRST L) 7)) ...)
  461.     is approximately equivalent to
  462.     (LET* ((#:G1 L) (#:G2 (FIRST #:G1)))
  463.       (UNWIND-PROTECT (PROGN (SETF (FIRST #:G1) 7) ...)
  464.                       (SETF (FIRST #:G1) #:G2)
  465.     ) )
  466.  
  467. 7.6.
  468. ----
  469.  
  470. WHEN, UNLESS, COND are implemented as special forms and, as such, rather
  471. efficient.
  472.  
  473. 7.8.4.
  474. ------
  475.  
  476. The function MAPCAP is like MAPCAN, except that it concatenates the
  477. resulting lists with APPEND instead of NCONC:
  478.   (MAPCAP fun x1 ... xn) == (apply #'append (mapcar fun x1 ... xn))
  479. (Actually a bit more efficient that this would be.)
  480.  
  481. The function MAPLAP is like MAPCON, except that it concatenates the
  482. resulting lists with APPEND instead of NCONC:
  483.   (MAPLAP fun x1 ... xn) = (apply #'append (maplist fun x1 ... xn))
  484. (Actually a bit more efficient that this would be.)
  485.  
  486. 7.9.1.
  487. ------
  488.  
  489. MULTIPLE-VALUES-LIMIT = 128
  490.  
  491. MULTIPLE-VALUE-LIST, MULTIPLE-VALUE-BIND, MULTIPLE-VALUE-SETQ are
  492. implemented as special forms and, as such, rather efficient.
  493.  
  494. The macro NTH-VALUE:
  495. (NTH-VALUE n form) returns the (n+1)st value (n>=0) of form.
  496.  
  497.  
  498.                         CHAPTER 8: Macros
  499.                         -----------------
  500.  
  501. 8.3.
  502. ----
  503.  
  504. The CLtL2 macro DESTRUCTURING-BIND is implemented. It does not perform full
  505. error checking.
  506.  
  507.  
  508.                      CHAPTER 9: Declarations
  509.                      -----------------------
  510.  
  511. 9.1.
  512. ----
  513.  
  514. The CLtL2 macro DECLAIM is implemented.
  515.  
  516. 9.2.
  517. ----
  518.  
  519. The declarations (TYPE type var ...), (FTYPE type fun ...),
  520. (FUNCTION name arglist result-type), (OPTIMIZE (quality value) ...)
  521. are ignored by the interpreter and the compiler.
  522.  
  523. The CLtL2 declaration (OPTIMIZE (DEBUG ...)) is legal.
  524.  
  525. Additional declarations:
  526.  
  527. * The dpANS declaration (IGNORABLE var ...) affects the variable binding for
  528.   the variable var. The compiler will not warn about the variable, regardless
  529.   whether it is used or not.
  530.  
  531. * The declaration (COMPILE) has the effect that the current form is compiled
  532.   prior to execution.
  533.   Examples:
  534.   (LOCALLY (DECLARE (COMPILE)) form)
  535.   executes a compiled version of form.
  536.   (let ((x 0))
  537.     (flet ((inc () (declare (compile)) (incf x))
  538.            (dec () (decf x)))
  539.       (values #'inc #'dec)
  540.   ) )
  541.   returns two functions. The first is compiled and increments x, the second
  542.   is interpreted (slower) and decrements the same x.
  543.  
  544. 9.3.
  545. ----
  546.  
  547. The type assertion (THE value-type form) enforces a type check in
  548. interpreted code. No type check is done in compiled code.
  549.  
  550. If using the optional package MACROS3:
  551. (ETHE value-type form) enforces a type check in both interpreted and
  552. compiled code.
  553.  
  554.  
  555.                          CHAPTER 10: Symbols
  556.                          -------------------
  557.  
  558. No notes.
  559.  
  560.  
  561.                          CHAPTER 11: Packages
  562.                          --------------------
  563.  
  564. 11.6.
  565. -----
  566.  
  567. The package SYSTEM has the nicknames "SYS" and, additionally, "COMPILER".
  568.  
  569. The CLtL2 packages
  570. * COMMON-LISP with nickname "CL" and
  571. * COMMON-LISP-USER with nickname "CL-USER"
  572. are implemented. The package COMMON-LISP exports only those symbols
  573. from the proposed ANSI CL draft that are actually implemented.
  574.  
  575. 11.7.
  576. -----
  577.  
  578. For MAKE-PACKAGE, the default value of the :USE argument is ("LISP" "CLOS").
  579.  
  580. The CLtL2 macro DEFPACKAGE is implemented.
  581.  
  582. 11.8.
  583. -----
  584.  
  585. The function REQUIRE receives as optional argument either a pathname or a
  586. list of pathnames: files to be loaded if the required module is not already
  587. in memory.
  588.  
  589.  
  590.                            CHAPTER 12: Numbers
  591.                            -------------------
  592.  
  593. The single and double float formats are those of the IEEE standard (1981),
  594. except that CLISP does not support features like +0, -0, +inf, -inf, gradual
  595. underflow, NaN, etc. (Common Lisp does not make use of these features.)
  596.  
  597. The default number of mantissa bits in long floats is given by the place
  598. (LONG-FLOAT-DIGITS).
  599. Example: (SETF (LONG-FLOAT-DIGITS) 3322) sets the default precision of long
  600. floats to 1000 decimal digits.
  601.  
  602. 12.1.
  603. -----
  604.  
  605. Complex numbers can have a real part and an imaginary part of different
  606. types. If the imaginary part is EQL to 0, the number is automatically
  607. converted to a real number. (Cf. CLtL1 p. 195)
  608. This has the advantage that  (let ((x (sqrt -9.0))) (* x x))
  609. - instead of evaluting to #C(-9.0 0.0), with x = #C(0.0 3.0) -
  610. evaluates to #C(-9.0 0) = -9.0, with x = #C(0 3.0).
  611.  
  612. Coercions on operations involving different types:
  613. The result of an arithmetic operation whose arguments are of different float
  614. types is rounded to the float format of the shortest (least precise) of the
  615. arguments.
  616.     rational -> long float -> double float -> single float -> short float
  617. (in contrast to CLtL1 p. 195!)
  618. Rationale:
  619.   See it mathematically. Add intervals:
  620.   {1.0 +/- 1e-8} + {1.0 +/- 1e-16} = {2.0 +/- 1e-8}
  621.   So, if we add 1.0s0 and 1.0d0, we should get 2.0s0.
  622. Shortly:
  623.   Do not suggest accuracy of a result by giving it a precision that is
  624.   greater than its accuracy.
  625. Example:
  626.   (- (+ 1.7 pi) pi)  should not return  1.700000726342836417234L0,
  627.   it should return 1.7f0 (or 1.700001f0 if there were rounding errors).
  628. Experience:
  629.   If in a computation using thousands of short floats, a long float (like pi)
  630.   happens to be used, the long precision should not propagate throughout all
  631.   the intermediate values. Otherwise, the long result would look precise,
  632.   but its accuracy is only that of a short float; furthermore much
  633.   computation time would be lost by calculating with long floats when only
  634.   short floats would be needed.
  635.  
  636. When rational numbers are to be converted to floats (due to FLOAT, COERCE,
  637. SQRT or a transcendental function), the result type is given by the variable
  638. *DEFAULT-FLOAT-FORMAT*.
  639.  
  640. The macro WITHOUT-FLOATING-POINT-UNDERFLOW:
  641.   (without-floating-point-underflow {form}*)
  642. executes the forms, with errors of type FLOATING-POINT-UNDERFLOW inhibited.
  643. Floating point operations will silently return zero instead of signalling
  644. an error of type FLOATING-POINT-UNDERFLOW.
  645.  
  646. 12.4.
  647. -----
  648.  
  649. (LCM), called without arguments, returns 1, which is the neutral element of
  650. composition with LCM.
  651.  
  652. (! n) returns the factorial of n, n a nonnegative integer.
  653.  
  654. (EXQUO x y) returns the quotient x/y of two integers x,y, and checks that it
  655. is an integer. (This is more efficient than /.)
  656.  
  657. (XGCD x1 ... xn) returns the values g, c1, ..., cn, where
  658. g is the greatest common divisor of the integers x1,...,xn,
  659. and c1,...,cn are integer coefficients such that
  660.   g = (GCD x1 ... xn) = (+ (* c1 x1) ... (* cn xn))
  661.  
  662. 12.5.1.
  663. -------
  664.  
  665. (EXPT base exponent) is not very precise if exponent has large absolute
  666. value.
  667.  
  668. (LOG number base) signals an error if base = 1.
  669.  
  670. 12.5.2.
  671. -------
  672.  
  673. The value of PI is a long float with the precision given by
  674. (LONG-FLOAT-DIGITS). When this precision is changed, the value of PI is
  675. automatically recomputed. Therefore PI is a variable, not a constant.
  676.  
  677. 12.6.
  678. -----
  679.  
  680. FLOAT-RADIX always returns 2.
  681.  
  682. (FLOAT-DIGITS number digits) coerces `number' (a real number) to a floating
  683. point number with at least `digits' mantissa digits. The following holds:
  684.    (>= (FLOAT-DIGITS (FLOAT-DIGITS number digits)) digits)
  685.  
  686. 12.7.
  687. -----
  688.  
  689. BOOLE-CLR   =  0
  690. BOOLE-SET   = 15
  691. BOOLE-1     = 10
  692. BOOLE-2     = 12
  693. BOOLE-C1    =  5
  694. BOOLE-C2    =  3
  695. BOOLE-AND   =  8
  696. BOOLE-IOR   = 14
  697. BOOLE-XOR   =  6
  698. BOOLE-EQV   =  9
  699. BOOLE-NAND  =  7
  700. BOOLE-NOR   =  1
  701. BOOLE-ANDC1 =  4
  702. BOOLE-ANDC2 =  2
  703. BOOLE-ORC1  = 13
  704. BOOLE-ORC2  = 11
  705.  
  706. 12.10.
  707. ------
  708.  
  709. MOST-POSITIVE-FIXNUM = 2^24-1 = 16777215
  710. MOST-NEGATIVE-FIXNUM = -2^24 = -16777216
  711.  
  712. Together with PI, the other long float constants MOST-POSITIVE-LONG-FLOAT,
  713. LEAST-POSITIVE-LONG-FLOAT, LEAST-NEGATIVE-LONG-FLOAT,
  714. MOST-NEGATIVE-LONG-FLOAT, LONG-FLOAT-EPSILON, LONG-FLOAT-NEGATIVE-EPSILON
  715. are recomputed whenever (LONG-FLOAT-DIGITS) is changed. They are variables,
  716. not constants.
  717.  
  718.  
  719.                          CHAPTER 13: Characters
  720.                          ----------------------
  721.  
  722. See first above: 2.2.
  723.  
  724. 13.1.
  725. -----
  726.  
  727. CHAR-CODE-LIMIT = 256
  728. CHAR-FONT-LIMIT = 16
  729. CHAR-BITS-LIMIT = 16
  730.  
  731. 13.2.
  732. -----
  733.  
  734. String-chars are those characters with font = 0 and bits = 0.
  735.  
  736. The graphic characters have been described above.
  737.  
  738. The standard characters are #\Newline and those graphic characters with a
  739. code between 32 and 126 (inclusive).
  740.  
  741. The alphabetic characters are these string-chars:
  742.              ABCDEFGHIJKLMNOPQRSTUVWXYZ
  743.              abcdefghijklmnopqrstuvwxyz
  744. and the international alphabetic characters from the character set:
  745.              ╟ⁿΘΓΣαστΩδΦ∩ε∞─┼╔µ╞⌠÷≥√∙ ╓▄▀ßφ≤·±╤¬║π⌡╪°└├╒ etc.
  746.  
  747. The functions CHAR-EQUAL, CHAR-NOT-EQUAL, CHAR-LESSP, CHAR-GREATERP,
  748. CHAR-NOT-GREATERP, CHAR-NOT-LESSP ignore bits and font attributes of their
  749. arguments.
  750.  
  751. 13.4.
  752. -----
  753.  
  754. The string chars that are not graphic chars and the space character have
  755. names:
  756.   (code-char #x00) = #\Null = #\Nul
  757.   (code-char #x01) = #\Soh
  758.   (code-char #x02) = #\Stx
  759.   (code-char #x03) = #\Etx
  760.   (code-char #x04) = #\Eot
  761.   (code-char #x05) = #\Enq
  762.   (code-char #x06) = #\Ack
  763.   (code-char #x07) = #\Bell = #\Bel
  764.   (code-char #x08) = #\Backspace = #\Bs
  765.   (code-char #x09) = #\Tab = #\Ht
  766.   (code-char #x0A) = #\Newline = #\Nl = #\Linefeed
  767.   (code-char #x0B) = #\Vt
  768.   (code-char #x0C) = #\Page = #\Np
  769.   (code-char #x0D) = #\Return = #\Cr
  770.   (code-char #x0E) = #\So
  771.   (code-char #x0F) = #\Si
  772.   (code-char #x10) = #\Dle
  773.   (code-char #x11) = #\Dc1
  774.   (code-char #x12) = #\Dc2
  775.   (code-char #x13) = #\Dc3
  776.   (code-char #x14) = #\Dc4
  777.   (code-char #x15) = #\Nak
  778.   (code-char #x16) = #\Syn
  779.   (code-char #x17) = #\Etb
  780.   (code-char #x18) = #\Can
  781.   (code-char #x19) = #\Em
  782.   (code-char #x1A) = #\Sub
  783.   (code-char #x1B) = #\Escape = #\Esc
  784.   (code-char #x1C) = #\Fs
  785.   (code-char #x1D) = #\Gs
  786.   (code-char #x1E) = #\Rs
  787.   (code-char #x1F) = #\Us
  788.   (code-char #x20) = #\Space = #\Sp
  789.   (code-char #x7F) = #\Rubout = #\Delete = #\Del
  790.  
  791. 13.5.
  792. -----
  793.  
  794. CHAR-CONTROL-BIT = 1
  795. CHAR-META-BIT    = 2
  796. CHAR-SUPER-BIT   = 4
  797. CHAR-HYPER-BIT   = 8
  798.  
  799.  
  800.                          CHAPTER 14: Sequences
  801.                          ---------------------
  802.  
  803. The CLtL2 function COMPLEMENT is implemented.
  804.  
  805. 14.1.
  806. -----
  807.  
  808. The result of NREVERSE is always EQ to the argument. NREVERSE on a vector
  809. swaps pairs of elements. NREVERSE on a list swaps the first and the last
  810. element and reverses the list chaining between them.
  811.  
  812. 14.2.
  813. -----
  814.  
  815. For iteration through a sequence, a macro DOSEQ, analogous to DOLIST, may be
  816. used instead of MAP :
  817.   (doseq (var seqform [resultform]) {declaration}* {tag|statement}* )
  818.  
  819. The CLtL2 function MAP-INTO is implemented.
  820.  
  821. 14.3.
  822. -----
  823.  
  824. REMOVE, REMOVE-IF, REMOVE-IF-NOT, REMOVE-DUPLICATES return their argument
  825. unchanged, if no element has to be removed.
  826.  
  827. DELETE, DELETE-IF, DELETE-IF-NOT, DELETE-DUPLICATES destructively modify
  828. their argument: If the argument is a list, the CDR parts are modified. If
  829. the argument is a vector with fill pointer, the fill pointer is lowered and
  830. the remaining elements are compacted below the new fill pointer.
  831.  
  832. 14.5.
  833. -----
  834.  
  835. SORT and STABLE-SORT have two additional keywords :START and :END :
  836.   (SORT sequence predicate &key :key :start :end)
  837.   (STABLE-SORT sequence predicate &key :key :start :end)
  838.  
  839. SORT and STABLE-SORT are identical. They implement the mergesort algorithm.
  840.  
  841.  
  842.                          CHAPTER 15: Lists
  843.                          -----------------
  844.  
  845. 15.4.
  846. -----
  847.  
  848. SUBLIS and NSUBLIS apply the :KEY argument to the nodes of the cons tree and
  849. not to the keys of the alist.
  850.  
  851.  
  852.                       CHAPTER 16: Hash Tables
  853.                       -----------------------
  854.  
  855. 16.1.
  856. -----
  857.  
  858. MAKE-HASH-TABLE has an additional keyword :INITIAL-CONTENTS :
  859.   (MAKE-HASH-TABLE &key :test :initial-contents :size :rehash-size
  860.                         :rehash-threshold)
  861. The :INITIAL-CONTENTS argument is an alist that is used to initialize the
  862. new hash table.
  863. The :REHASH-THRESHOLD argument is ignored.
  864.  
  865. For iteration through a hash table, a macro DOHASH, analogous to DOLIST, can
  866. be used instead of MAPHASH :
  867.   (dohash (key-var value-var hash-table-form [resultform])
  868.     {declaration}* {tag|statement}*
  869.   )
  870.  
  871.  
  872.                      CHAPTER 17: Arrays
  873.                      ------------------
  874.  
  875. 17.1.
  876. -----
  877.  
  878. MAKE-ARRAY can return specialized arrays for the element types
  879. (UNSIGNED-BYTE 2), (UNSIGNED-BYTE 4), (UNSIGNED-BYTE 8), (UNSIGNED-BYTE 16),
  880. (UNSIGNED-BYTE 32) and of course BIT and STRING-CHAR.
  881.  
  882. ARRAY-RANK-LIMIT is 65536 on 16-bit processors, 4294967296 on 32-bit
  883. processors.
  884.  
  885. ARRAY-DIMENSION-LIMIT  = 2^24 = 16777216
  886. ARRAY-TOTAL-SIZE-LIMIT = 2^24 = 16777216
  887.  
  888. 17.6.
  889. -----
  890.  
  891. An array to which another array is displaced should not be shrunk (using
  892. ADJUST-ARRAY) in such a way that the other array points into void space.
  893. This is not checked at the time ADJUST-ARRAY is called!
  894.  
  895.  
  896.                        CHAPTER 18: Strings
  897.                        -------------------
  898.  
  899. 18.2.
  900. -----
  901.  
  902. String comparison is based on the function CHAR<=. Therefore diphtongs do
  903. not obey the usual national rules. Example: "o" < "oe" < "z" < "÷".
  904.  
  905.  
  906.                         CHAPTER 19: Structures
  907.                         ----------------------
  908.  
  909. 19.5.
  910. -----
  911.  
  912. The :PRINT-FUNCTION option should contain a lambda expression
  913.   (lambda (structure stream depth) (declare (ignore depth)) ...)
  914. This lambda expression names a function whose task is to output the external
  915. representation of structure onto the stream. This may be done by outputting
  916. text onto the stream using WRITE-CHAR, WRITE-STRING, WRITE, PRIN1, PRINC,
  917. PRINT, PPRINT, FORMAT and the like. The following rules must be obeyed:
  918. * The value of *PRINT-ESCAPE* must be respected.
  919. * The value of *PRINT-PRETTY* should not and cannot be respected, since the
  920.   pretty-print mechanism is not accessible from outside.
  921. * The value of *PRINT-CIRCLE* need not to be respected. This is managed by
  922.   the system. (But the print-circle mechanism handles only those objects that
  923.   are (direct or indirect) components of structure.)
  924. * The value of *PRINT-LEVEL* is respected by
  925.   WRITE, PRIN1, PRINC, PRINT, PPRINT, FORMAT ~A, FORMAT ~S, FORMAT ~W and
  926.   FORMAT ~D,~B,~O,~X,~R,~F,~E,~G,~$ with not-numerical arguments.
  927.   Therefore the print-level mechanism works automatically if only these
  928.   functions are used for outputting objects and if they are not called on
  929.   objects with nesting level > 1. (The print-level mechanism does not
  930.   recognize how many parentheses you have output. It only counts how many
  931.   times it was called recursively.)
  932. * The value of *PRINT-LENGTH* must be respected, especially if you are
  933.   outputting an arbitrary number of components.
  934. * The value of *PRINT-READABLY* must be respected. Remember that the values
  935.   of *PRINT-ESCAPE*, *PRINT-LEVEL*, *PRINT-LENGTH* don't matter if
  936.   *PRINT-READABLY* is true.
  937.   The value of *PRINT-READABLY* is respected by PRINT-UNREADABLE-OBJECT,
  938.   WRITE, PRIN1, PRINC, PRINT, PPRINT, FORMAT ~A, FORMAT ~S, FORMAT ~W and
  939.   FORMAT ~D,~B,~O,~X,~R,~F,~E,~G,~$ with not-numerical arguments.
  940.   Therefore *PRINT-READABLY* will be respected automatically if only these
  941.   functions are used for outputting objects.
  942. * You need not bother about the values of *PRINT-BASE*, *PRINT-RADIX*,
  943.   *PRINT-CASE*, *PRINT-GENSYM*, *PRINT-ARRAY*, *PRINT-CLOSURE*, *PRINT-RPARS*,
  944.   *PRINT-INDENT-LISTS*.
  945.  
  946. The :INHERIT option is exactly like :INCLUDE except that it doesn't create
  947. new accessors for the inherited slots. Use this option to avoid the problems
  948. that occur when using the same :CONC-NAME for the new and the inherited
  949. structure.
  950.  
  951.  
  952.                        CHAPTER 20: The Evaluator
  953.                        -------------------------
  954.  
  955. As in Scheme, the Macro (THE-ENVIRONMENT) returns the current lexical
  956. environment. This works only in interpreted code and is not compilable!
  957.  
  958. (EVAL-ENV form [env]) evaluates a form in a given lexical environment, just
  959. if the form had been part of the program text that environment came from.
  960.  
  961.  
  962.                          CHAPTER 21: Streams
  963.                          -------------------
  964.  
  965. 21.1.
  966. -----
  967.  
  968. Input through *TERMINAL-IO* uses the GNU readline library. Arrow keys can be
  969. used to move within the input history. The Tab key completes the symbol's
  970. name that is being typed.
  971. See readline.dvi for a complete description of the key bindings.
  972. The GNU readline library is not used if standard input and standard output do
  973. not both refer to the same terminal.
  974.  
  975. *TERMINAL-IO* is not the only stream that communicates directly with the
  976. user: During execution of the body of a (WITH-KEYBOARD . body) form,
  977. *KEYBOARD-INPUT* is the stream that reads the keystrokes from the keyboard.
  978. It returns every keystroke in detail, as character with the following bits:
  979.   CHAR-CODE    the Ascii code for standard keys,
  980.                for non-standard keys:
  981.                  F1 -> #\F1, ..., F10 -> #\F10, F11 -> #\F11, F12 -> #\F12,
  982.                  Insert -> #\Insert, Delete -> #\Delete, Center -> #\Center,
  983.                  Home -> #\Home, End -> #\End, PgUp -> #\PgUp, PgDn -> #\PgDn,
  984.                  Arrow keys -> #\Up, #\Down, #\Left, #\Right.
  985.   CONTROL      if pressed together with the Control key.
  986. This keyboard input is not echoed on the screen.
  987. During execution of a (WITH-KEYBOARD . body) form, no input from *TERMINAL-IO*
  988. or any synonymous stream should be requested.
  989.  
  990. 21.2.
  991. -----
  992.  
  993. The macro WITH-OUTPUT-TO-PRINTER
  994.        (with-output-to-printer (var) {declaration}* {form}*)
  995. binds the variable var to an output stream that sends its output to the
  996. printer.
  997.  
  998. (MAKE-PIPE-INPUT-STREAM command) returns an input stream that will supply the
  999. output from the execution of the given operating system command.
  1000. See also (SHELL command).
  1001.  
  1002. (MAKE-PIPE-OUTPUT-STREAM command) returns an output stream that will pass its
  1003. output as input to the execution of the given operating system command.
  1004. See also (SHELL command).
  1005.  
  1006. (MAKE-PIPE-IO-STREAM command) returns three values. The first value is a
  1007. bidirectional stream that will simultaneously pass its output as input to
  1008. the execution of the given operating system command and supply the output
  1009. from this command as input. The second and third value will be the input
  1010. stream and the output stream that make up the I/O stream, respectively.
  1011. Note that they must be closed individually.
  1012. Warning: Improper use of this function can lead to deadlocks. You use it at
  1013. your own risk!
  1014. A deadlock occurs if the command and your program either both try to read
  1015. from each other at the same time or both try to write to each other at
  1016. the same time. To avoid deadlocks, it is recommended that you fix a protocol
  1017. between the command and your program and avoid any hidden buffering: Use
  1018. READ-CHAR, READ-CHAR-NO-HANG, LISTEN instead of READ-LINE and READ on the
  1019. input side, and complete every output operation by a FINISH-OUTPUT. The same
  1020. cautions must apply to the called command as well.
  1021. See also (SHELL command).
  1022.  
  1023. Generic streams are user programmable streams. The programmer interface:
  1024.  
  1025.   (MAKE-GENERIC-STREAM controller) returns a generic stream.
  1026.  
  1027.   (GENERIC-STREAM-CONTROLLER stream)
  1028.      returns a private object to which generic stream methods dispatch.
  1029.      The typical usage is to retrieve the object originally provided by the
  1030.      user in MAKE-GENERIC-STREAM.
  1031.  
  1032.   (GENERIC-STREAM-P stream)
  1033.     determines whether a stream is a generic stream, returning T if it is,
  1034.     NIL otherwise.
  1035.  
  1036. In order to specify the behaviour of a generic stream, the user must define
  1037. CLOS methods on the following CLOS generic functions. The function
  1038. GENERIC-STREAM-XYZ corresponds to the Common Lisp function XYZ. They all
  1039. take a controller and some number of arguments.
  1040.  
  1041.   (GENERIC-STREAM-READ-CHAR    controller)
  1042.   (GENERIC-STREAM-READ-BYTE    controller)
  1043.          These generic functions should return NIL at end of file.
  1044.          Takes one argument, the controller object.
  1045.   (GENERIC-STREAM-LISTEN       controller)
  1046.          Returns -1 for EOF, 0 for character pending, and 1 for none.
  1047.          Takes one argument, the controller object.
  1048.   (GENERIC-STREAM-WRITE-CHAR   controller ch)
  1049.          First argument is the controller object.
  1050.          Second argument is the character to be written.
  1051.   (GENERIC-STREAM-WRITE-BYTE   controller by)
  1052.          First argument is the controller object.
  1053.          Second argument is the integer to be written.
  1054.   (GENERIC-STREAM-WRITE-STRING controller string start len)
  1055.          Called with argument list (controller string start len),
  1056.          this function shall write
  1057.            (subseq (the string string) start (+ start len))
  1058.          First argument is the controller object.
  1059.   (GENERIC-STREAM-CLEAR-INPUT   controller)
  1060.   (GENERIC-STREAM-CLEAR-OUTPUT  controller)
  1061.   (GENERIC-STREAM-FINISH-OUTPUT controller)
  1062.   (GENERIC-STREAM-FORCE-OUTPUT  controller)
  1063.   (GENERIC-STREAM-CLOSE         controller)
  1064.          Takes one argument, the controller object.
  1065.  
  1066. 21.3.
  1067. -----
  1068.  
  1069. The CLtL2 function OPEN-STREAM-P is implemented.
  1070.  
  1071. CLOSE ignores its :ABORT argument.
  1072.  
  1073. The CLtL2 functions BROADCAST-STREAM-STREAMS, CONCATENATED-STREAM-STREAMS,
  1074. ECHO-STREAM-INPUT-STREAM, ECHO-STREAM-OUTPUT-STREAM, SYNONYM-STREAM-SYMBOL,
  1075. TWO-WAY-STREAM-INPUT-STREAM, TWO-WAY-STREAM-OUTPUT-STREAM are implemented.
  1076.  
  1077.  
  1078.                      CHAPTER 22: Input/Output
  1079.                      ------------------------
  1080.  
  1081. 22.1.2.
  1082. -------
  1083.  
  1084. A "reserved token", i.e. a token that has potential number syntax but cannot
  1085. be interpreted as a number, is interpreted as symbol when being read. (CLtL1
  1086. p. 341)
  1087.  
  1088. When a token with package markers is read, then (CLtL1 p. 343/344) no
  1089. checking is done whether the package part and the symbol-name part do not
  1090. have number syntax. (What's the purpose of this check?) So we consider
  1091. tokens like USER:: or :1 or LISP::4711 or 21:3 as symbols.
  1092.  
  1093. 22.1.3.
  1094. -------
  1095.  
  1096. The backquote read macro also works when nested. Example:
  1097.  (eval ``(,#'(lambda () ',a) ,#'(lambda () ',b)))
  1098.  = (eval `(list #'(lambda () ',a) #'(lambda () ',b)))
  1099.  = (eval (list 'list (list 'function (list 'lambda nil (list 'quote a)))
  1100.                      (list 'function (list 'lambda nil (list 'quote b)))
  1101.    )     )
  1102.  
  1103. Multiple backquote combinations like ,,@ or ,@,@ are not implemented. Their
  1104. use would be confusing anyway.
  1105.  
  1106. 22.1.4.
  1107. -------
  1108.  
  1109. #\ allows inputting characters of arbitrary code: #\Code231 yields the
  1110. character (code-char 231.).
  1111.  
  1112. Additional read dispatch macros:
  1113. * #Y is used to read compiled functions.
  1114. * #" is used to read pathnames:
  1115.      #"test.lsp" is the value of (pathname "test.lsp")
  1116.  
  1117. 22.1.5.
  1118. -------
  1119.  
  1120. Is it impossible to get the read macro function of a dispatch macro
  1121. character like #\# using GET-MACRO-CHARACTER.
  1122.  
  1123. The CLtL2 place READTABLE-CASE is implemented. The possible values of
  1124. (READTABLE-CASE readtable) are :UPCASE, :DOWNCASE and :PRESERVE.
  1125.  
  1126. 22.1.6.
  1127. -------
  1128.  
  1129. In absence of SYS::WRITE-FLOAT, floating point numbers are output in radix 2.
  1130.  
  1131. If *PRINT-READABLY* is true, *READ-DEFAULT-FLOAT-FORMAT* has no influence on
  1132. the way floating point numbers are printed.
  1133.  
  1134. Pathnames are written according to the syntax #"namestring" if
  1135. *PRINT-ESCAPE* /= NIL. If *PRINT-ESCAPE* = NIL, only the namestring is
  1136. printed.
  1137.  
  1138. *PRINT-CASE* controls the output not only of symbols, but also of characters
  1139. and some #<...> objects.
  1140.  
  1141. *PRINT-PRETTY* is initially = NIL but set to T in config.lsp. This makes
  1142. screen output prettier.
  1143.  
  1144. *PRINT-ARRAY* is initially = T.
  1145.  
  1146. An additional variable *PRINT-CLOSURE* controls whether compiled and
  1147. interpreted functions (closures) are output in detailed form. If
  1148. *PRINT-CLOSURE* /= NIL, compiled closures are output in #Y syntax the reader
  1149. understands. *PRINT-CLOSURE* is initially = NIL.
  1150.  
  1151. An additional variable *PRINT-RPARS* controls the output of right (closing)
  1152. parentheses. If *PRINT-RPARS* /= NIL, closing parentheses which don't fit
  1153. onto the same line as the the corresponding opening parenthesis are output
  1154. just below their corresponding opening parenthesis, in the same column.
  1155. *PRINT-RPARS* is initially = T.
  1156.  
  1157. An additional variable *PRINT-INDENT-LISTS* controls the indentation of lists
  1158. that span more than one line. It specifies by how many characters items
  1159. within the list will be indented relative to the beginning of the list.
  1160. *PRINT-INDENT-LISTS* is initially = 2.
  1161.  
  1162. The CLtL2 macro WITH-STANDARD-IO-SYNTAX is implemented.
  1163.  
  1164. 22.2.1.
  1165. -------
  1166.  
  1167. The function READ-CHAR-SEQUENCE performs multiple READ-CHAR operations:
  1168. (READ-CHAR-SEQUENCE sequence stream [:start] [:end]) fills the
  1169. subsequence of sequence specified by :start and :end with characters
  1170. consecutively read from stream. It returns the index of the first element
  1171. of sequence that was not updated (= end or < end if the stream reached its
  1172. end).
  1173. This function is especially efficient if sequence is a string and stream is
  1174. a file stream with element type STRING-CHAR, a pipe stream or a string input
  1175. stream.
  1176.  
  1177. 22.2.2.
  1178. -------
  1179.  
  1180. The function READ-BYTE-SEQUENCE performs multiple READ-BYTE operations:
  1181. (READ-BYTE-SEQUENCE sequence stream [:start] [:end]) fills the
  1182. subsequence of sequence specified by :start and :end with integers
  1183. consecutively read from stream. It returns the index of the first element
  1184. of sequence that was not updated (= end or < end if the stream reached its
  1185. end).
  1186. This function is especially efficient if sequence is a
  1187. (VECTOR (UNSIGNED-BYTE 8)) and stream is a file stream with element type
  1188. (UNSIGNED-BYTE 8) or a pipe stream.
  1189.  
  1190. 22.3.1.
  1191. -------
  1192.  
  1193. The functions WRITE and WRITE-TO-STRING have an additional keyword :CLOSURE
  1194. that can be used to bind *PRINT-CLOSURE*.
  1195.  
  1196. The CLtL2 macro PRINT-UNREADABLE-OBJECT is implemented.
  1197.  
  1198. The function WRITE-CHAR-SEQUENCE performs multiple WRITE-CHAR operations:
  1199. (WRITE-CHAR-SEQUENCE sequence stream [:start] [:end]) outputs the characters
  1200. of the subsequence of sequence specified by :start and :end to stream.
  1201. It returns sequence.
  1202. This function is especially efficient if sequence is a string and stream is
  1203. a file stream with element type STRING-CHAR or a pipe stream.
  1204.  
  1205. 22.3.2.
  1206. -------
  1207.  
  1208. The function WRITE-BYTE-SEQUENCE performs multiple WRITE-BYTE operations:
  1209. (WRITE-BYTE-SEQUENCE sequence stream [:start] [:end]) outputs the integers
  1210. of the subsequence of sequence specified by :start and :end to stream.
  1211. It returns sequence.
  1212. This function is especially efficient if sequence is a
  1213. (VECTOR (UNSIGNED-BYTE 8)) and stream is a file stream with element type
  1214. (UNSIGNED-BYTE 8) or a pipe stream.
  1215.  
  1216. 22.3.3.
  1217. -------
  1218.  
  1219. The FORMAT option ~W is analogous to ~A and ~S, but avoids binding of
  1220. *PRINT-ESCAPE*. (FORMAT stream "~W" object) is equivalent to
  1221. (WRITE object :stream stream).
  1222.  
  1223. FORMAT ~R and FORMAT ~:R can output only integers in the range |n| < 10^66.
  1224. The output is in English, according to the American conventions, and these
  1225. conventions are identical to the British conventions only in the range
  1226. |n| < 10^9.
  1227.  
  1228. FORMAT ~:@C does not output the character itself, only the instruction how
  1229. to type the character.
  1230.  
  1231. For FORMAT ~E and FORMAT ~G, the value of *READ-DEFAULT-FLOAT-FORMAT* doesn't
  1232. matter if *PRINT-READABLY* is true.
  1233.  
  1234. FORMAT ~T can determine the current column of any stream.
  1235.  
  1236.  
  1237.                     CHAPTER 23: File System Interface
  1238.                     ---------------------------------
  1239.  
  1240. 23.1.
  1241. -----
  1242.  
  1243. For most operations, pathnames denoting files and pathnames denoting
  1244. directories can not be used interchangeably.
  1245. For example, #"FOO/BAR" denotes the file BAR in the directory FOO, while
  1246. #"FOO/BAR/" denotes the subdirectory BAR of the directory FOO.
  1247. This is especially important for the functions DIRECTORY, DIR, CD, MAKE-DIR,
  1248. DELETE-DIR.
  1249.  
  1250. The minimum filename syntax that may be used portably is:
  1251.   "xxx"       for a file with name xxx,
  1252.   "xxx.yy"    for a file with name xxx and type yy,
  1253.   ".yy"       for a pathname with type yy and no name specified.
  1254. Hereby xxx denote 1 to 8 characters, and yy denote 1 to 3 characters, each of
  1255. which being either alphanumerical or the underscore #\_.
  1256. Other properties of pathname syntax vary between operating systems.
  1257.  
  1258. 23.1.1.
  1259. -------
  1260.  
  1261. Pathname components:
  1262. HOST          always NIL
  1263. DEVICE        always NIL
  1264. DIRECTORY     (startpoint . subdirs) where
  1265.                startpoint = :RELATIVE | :ABSOLUTE
  1266.                subdirs = () | (subdir . subdirs)
  1267.                subdir = :WILD-INFERIORS (means "**" or "...", all subdirectories) or
  1268.                subdir = simple string, may contain wildcard characters ? and *
  1269. NAME          NIL or
  1270.               simple string, may contain wildcard characters ? and *
  1271.               (may also be specified as :WILD)
  1272. TYPE          NIL or
  1273.               simple string, may contain wildcard characters ? and *
  1274.               (may also be specified as :WILD)
  1275. VERSION       always NIL (may also be specified as :WILD or :NEWEST)
  1276.  
  1277. A UNIX filename is split into name and type according to the following rule:
  1278.   if there is no '.' in the filename, then the name is everything, type = NIL;
  1279.   if there is a '.', then name is the part before and type the part after
  1280.      the last dot.
  1281.  
  1282. When a pathname is to be fully specified (no wildcards), that means that
  1283. no :WILD, :WILD-INFERIORS is allowed, no wildcard characters are allowed in
  1284. the strings, and NAME = NIL may not be allowed either.
  1285.  
  1286. External notation:   server:sub1.typ/sub2.typ/name.typ
  1287. using defaults:             sub1.typ/sub2.typ/name.typ
  1288. or                                            name.typ
  1289. or                          sub1.typ/**/sub3.typ/x*.lsp
  1290. or similar.
  1291.  
  1292. The wildcard characters: '*' matches any sequence of characters, '?' matches
  1293. any one character.
  1294.  
  1295. Due to the name/type splitting rule, there are pathnames that can't result
  1296. from PARSE-NAMESTRING. To get a pathname whose type contains a dot or whose
  1297. name contains a dot and whose type is NIL, MAKE-PATHNAME must be used.
  1298. Example: (MAKE-PATHNAME :NAME ".profile").
  1299.  
  1300. 23.1.2.
  1301. -------
  1302.  
  1303. External notation of pathnames (cf. PARSE-NAMESTRING and NAMESTRING),
  1304. of course without spaces, [,],{,}:
  1305.  [ / ]                 / denotes absolute pathnames
  1306.  { name / }            each one a subdirectory
  1307.  [ name [. type] ]     filename with type (extension)
  1308.  
  1309. Name and type may be character sequences of any length (consisting of
  1310. printing ASCII characters, except '/').
  1311.  
  1312. NAMESTRING has an optional flag argument: (NAMESTRING pathname T) returns an
  1313. external notation suitable for passing to the operating system or other
  1314. programs.
  1315.  
  1316. 23.1.4.
  1317. -------
  1318.  
  1319. The CLtL2 functions WILD-PATHNAME-P, PATHNAME-MATCH-P and TRANSLATE-PATHNAME
  1320. are implemented.
  1321.  
  1322. PATHNAME-MATCH-P does not interpret missing components as wild.
  1323.  
  1324. TRANSLATE-PATHNAME has two additional keywords:
  1325.   (TRANSLATE-PATHNAME source from-wildname to-wildname &key :all :merge)
  1326. If :ALL is specified and non-NIL, a list of all resulting pathnames,
  1327. corresponding to all matches of (PATHNAME-MATCH-P source from-wildname),
  1328. is returned. If :MERGE is specified and NIL, unspecified pieces of to-pathname
  1329. are not replaced by corresponding pieces of source.
  1330.  
  1331. 23.1.5.
  1332. -------
  1333.  
  1334. The functions LOGICAL-PATHNAME, TRANSLATE-LOGICAL-PATHNAME,
  1335. LOGICAL-PATHNAME-TRANSLATIONS, (SETF LOGICAL-PATHNAME-TRANSLATIONS),
  1336. LOAD-LOGICAL-PATHNAME-TRANSLATIONS, COMPILE-FILE-PATHNAME are implemented.
  1337.  
  1338. RENAME-FILE always returns a non-logical pathname as its first value.
  1339.  
  1340. 23.1.6.
  1341. -------
  1342.  
  1343. (PARSE-NAMESTRING string [host [defaults]]) returns a logical pathname only
  1344. if host is a logical host or host is NIL and defaults is a logical pathname.
  1345. To construct a logical pathname from a string, the function LOGICAL-PATHNAME
  1346. can be used.
  1347.  
  1348. (MERGE-PATHNAMES string [defaults]) returns a logical pathname only if
  1349. defaults is a logical pathname. To construct a logical pathname from a string,
  1350. the function LOGICAL-PATHNAME can be used.
  1351.  
  1352. 23.2.
  1353. -----
  1354.  
  1355. OPEN cannot handle files of size >= 16 MB.
  1356.  
  1357. The file streams returned by OPEN are buffered for regular files and
  1358. unbuffered for special files.
  1359.  
  1360. 23.3.
  1361. -----
  1362.  
  1363. PROBE-FILE can not be used to check whether a directory exists. Use the
  1364. function DIRECTORY for this purpose.
  1365.  
  1366. FILE-AUTHOR always returns NIL.
  1367.  
  1368. 23.4.
  1369. -----
  1370.  
  1371. LOAD has two additional keywords :ECHO and :COMPILING.
  1372. (LOAD filename &key :verbose :print :echo :if-does-not-exist :compiling)
  1373. :VERBOSE T   causes LOAD to emit a short message that a file is being loaded.
  1374.              The default is *LOAD-VERBOSE*, which is initially = T.
  1375. :PRINT T     causes LOAD to print the value of each form.
  1376.              The default is *LOAD-PRINT*, which is initially = NIL.
  1377. :ECHO T      causes the input from the file to be echoed to *STANDARD-OUTPUT*
  1378.              (normally to the screen). Should there be an error in the file,
  1379.              you can see at one glance where it is.
  1380.              The default is *LOAD-ECHO*, which is initially = NIL.
  1381. :COMPILING T causes each form read to be compiled on the fly. The compiled
  1382.              code is executed at once and - in contrast to COMPILE-FILE -
  1383.              not written to a file.
  1384.  
  1385. The CLtL2 variables *LOAD-PATHNAME* and *LOAD-TRUENAME* are implemented.
  1386.  
  1387. The variable *LOAD-PATHS* contains a list of directories where program files
  1388. are searched - additionally to the specified or current directory - by LOAD,
  1389. REQUIRE, COMPILE-FILE.
  1390.  
  1391. 23.5.
  1392. -----
  1393.  
  1394. (DIRECTORY [pathname [:full] [:circle]]) can run in two modes:
  1395. * If pathname contains no name or type component, a list of all matching
  1396.   directories is produced.
  1397. * Otherwise a list of all matching files is returned. If the :FULL argument
  1398.   is /= NIL, this contains additional information: for each matching file
  1399.   you get a list of at least four elements
  1400.   (file-pathname file-truename file-write-date-as-decoded-time file-length).
  1401. If the :CIRCLE argument is /= NIL, the function avoids endless loops that
  1402. may result from symbolic links.
  1403.  
  1404. (DIR [pathname]) is like DIRECTORY, but displays the pathnames instead of
  1405. returning them. (DIR) shows the contents of the current directory.
  1406.  
  1407. (CD [pathname]) manages the current directory.
  1408. (CD pathname) sets it, (CD) returns it.
  1409.  
  1410. (DEFAULT-DIRECTORY) is equivalent to (CD), (SETF (DEFAULT-DIRECTORY) pathname)
  1411. is equivalent to (CD pathname).
  1412.  
  1413. (MAKE-DIR directory-pathname) creates a new subdirectory.
  1414.  
  1415. (DELETE-DIR directory-pathname) removes an (empty) subdirectory.
  1416.  
  1417. (EXECUTE programfile arg1 arg2 ...)  executes an external program. Its name
  1418. is programfile. It is given the strings arg1, arg2, ... as arguments.
  1419.  
  1420. (SHELL [command])  calls the operating system's shell.
  1421. (SHELL) calls the shell for interactive use. (SHELL command) calls the shell
  1422. only for execution of the one given command.
  1423.  
  1424. The functions RUN-SHELL-COMMAND and RUN-PROGRAM are a general interface to
  1425. SHELL and the above:
  1426.   (RUN-SHELL-COMMAND command [:input] [:output] [:if-output-exists])
  1427.     runs a shell command.
  1428.   (RUN-PROGRAM program [:arguments] [:input] [:output] [:if-output-exists])
  1429.     runs an external program.
  1430. The command argument     specifies the shell command.
  1431. The program argument     specifies the program. The directories listed in the
  1432.                          PATH environment veriable will be searched for it.
  1433. The :arguments argument  specifies a list of arguments (strings) that are
  1434.                          given to the program.
  1435. The :input argument      specifies where the program's input is to come from:
  1436.                          either :TERMINAL (the standard input) or :STREAM
  1437.                          (a Lisp stream to be created) or a pathname (an
  1438.                          input file) or NIL (no input at all).
  1439. The :output argument     specifies where the program's output is to be sent
  1440.                          to: either :TERMINAL (the standard output) or :STREAM
  1441.                          (a Lisp stream to be created) or a pathname (an
  1442.                          output file) or NIL (ignore the output).
  1443. The :if-output-exists argument specifies what to do if the :output file
  1444.                          already exists. The possible values are :overwrite,
  1445.                          :append, :error, with the same meaning as for OPEN.
  1446. If :STREAM was specified for :input or :output, a Lisp stream is returned.
  1447. If :STREAM was specified for :input and :output, three Lisp streams are
  1448. returned, as for the function MAKE-PIPE-IO-STREAM. This use of RUN-PROGRAM
  1449. can cause deadlocks, see MAKE-PIPE-IO-STREAM.
  1450.  
  1451.  
  1452.                         CHAPTER 24: Errors
  1453.                         ------------------
  1454.  
  1455. 24.1.
  1456. -----
  1457.  
  1458. When an error occurred, you are in a break loop. You can evaluate forms as
  1459. usual. The HELP command (or help key if there is one) lists the available
  1460. debugging commands.
  1461.  
  1462.  
  1463.                   CHAPTER 25: Miscellaneous Features
  1464.                   ----------------------------------
  1465.  
  1466. 25.1.
  1467. -----
  1468.  
  1469. The compiler can be called not only by the functions COMPILE, COMPILE-FILE
  1470. and DISASSEMBLE, also by the declaration (COMPILE).
  1471.  
  1472. (COMPILE-FILE input-file [:output-file] [:listing]
  1473.                          [:warnings] [:verbose] [:print])
  1474. compiles a file to bytecode.
  1475.     input-file                should be a pathname/string/symbol.
  1476. The :output-file argument     should be NIL or T or a pathname/string/symbol
  1477.                               or an output-stream. The default is T.
  1478. The :listing argument         should be NIL or T or a pathname/string/symbol
  1479.                               or an output-stream. The default is NIL.
  1480. The :warnings argument        specifies whether warnings should also appear
  1481.                               on the screen.
  1482. The :verbose argument         specifies whether error messages should also
  1483.                               appear on the screen.
  1484. The :print argument           specifies whether an indication which forms are
  1485.                               being compiled should appear on the screen.
  1486. The variables *COMPILE-WARNINGS*, *COMPILE-VERBOSE*, *COMPILE-PRINT* provide
  1487. defaults for the :warnings, :verbose, :print keyword arguments, respectively.
  1488. For each input file (default file type: #".lsp") the following files are
  1489. generated:
  1490.   output file              only if :output-file is not NIL
  1491.                            default file type: #".fas"
  1492.                            contents: can be loaded using the LOAD function.
  1493.   auxiliary output file    only if :output-file is not NIL
  1494.                            default file type: #".lib"
  1495.                            contents: used by COMPILE-FILE when compiling
  1496.                              a REQUIRE form referring to the input file.
  1497.   listing file             only if :listing is not NIL
  1498.                            default file type: #".lis"
  1499.                            contents: disassembly of the output file.
  1500.   C output file            only if :output-file is not NIL
  1501.                            default file type: #".c"
  1502.                            contents: foreign function interface
  1503.                            this file is deleted if it is empty.
  1504.  
  1505. The CLtL2 variables *COMPILE-FILE-PATHNAME* and *COMPILE-FILE-TRUENAME* are
  1506. implemented.
  1507.  
  1508. The CLtL2 special form LOAD-TIME-VALUE is implemented. (LOAD-TIME-VALUE form)
  1509. is like (QUOTE #,form) except that the former can be generated by macros.
  1510.  
  1511. DISASSEMBLE can disassemble to machine code, provided that GNU gdb is present.
  1512. In that case the argument may be a SYSTEM-FUNCTION, a FOREIGN-FUNCTION, a
  1513. special form indicator, a symbol denoting one of these, a number, or a string.
  1514.  
  1515. The CLtL2 function FUNCTION-LAMBDA-EXPRESSION is implemented.
  1516. (FUNCTION-LAMBDA-EXPRESSION function) returns information about the source
  1517. of an interpreted function: lambda-expression, lexical environment, name.
  1518.  
  1519. 25.2.
  1520. -----
  1521.  
  1522. No on-line documentation is available for the system functions (yet).
  1523.  
  1524. 25.3.
  1525. -----
  1526.  
  1527. (TRACE fun ...) makes the functions fun, ... traced. Syntax of fun:
  1528. Either a symbol:
  1529.        symbol
  1530. or a list of a symbol and some keywords and arguments (which must come in
  1531. pairs!):
  1532.        (symbol
  1533.          [:suppress-if form]   ; no trace output as long as form is true
  1534.          [:step-if form]       ; invokes the stepper as soon as form is true
  1535.          [:pre form]           ; evaluates form before calling the function
  1536.          [:post form]          ; evaluates form after return from the function
  1537.          [:pre-break-if form]  ; goes into the break loop before calling the
  1538.                                ; function if form is true
  1539.          [:post-break-if form] ; goes into the break loop after return from
  1540.                                ; the function if form is true
  1541.          [:pre-print form]     ; prints the values of form before calling the
  1542.                                ; function
  1543.          [:post-print form]    ; prints the values of form after return from
  1544.                                ; the function
  1545.          [:print form]         ; prints the values of form both before
  1546.                                ; calling and after return from the function
  1547.        )
  1548. In all these forms you can access
  1549.   the function itself               as *TRACE-FUNCTION*,
  1550.   the arguments to the function     as *TRACE-ARGS*,
  1551.   the function/macro call as form   as *TRACE-FORM*,
  1552. and after return from the function
  1553.   the list of return values from the function call  as *TRACE-VALUES*,
  1554. and you can leave the function call with specified values by using RETURN.
  1555.  
  1556. TRACE and UNTRACE are also applicable to functions (SETF symbol) and to macros,
  1557. but not to locally defined functions and macros.
  1558.  
  1559. The function INSPECT is not implemented.
  1560.  
  1561. The function ROOM can only be called without arguments. It returns two values:
  1562. the number of bytes currently occupied by Lisp objects, and the number of
  1563. bytes that can be allocated before the next regular garbage collection occurs.
  1564.  
  1565. The function ED calls the external editor specified by the variable *EDITOR*
  1566. (see config.lsp).
  1567. If using the optional package EDITOR:
  1568.   ED behaves like this only if the variable *USE-ED* is NIL.
  1569.   Otherwise ED uses an Emacs-like screen editor with multiple windows.
  1570.  
  1571. The function UNCOMPILE does the converse of COMPILE: (UNCOMPILE function-name)
  1572. reverts an interpreted function that has been entered or loaded in the same
  1573. session and then compiled back to its interpreted form.
  1574.  
  1575. 25.4.1.
  1576. -------
  1577.  
  1578. The timezone in a decoded time must not necessarily be an integer, but (as
  1579. float or rational number) it should be a multiple of 1/4.
  1580.  
  1581. INTERNAL-TIME-UNITS-PER-SECOND = 1000000.
  1582.  
  1583. 25.4.2.
  1584. -------
  1585.  
  1586. The functions MACHINE-TYPE, MACHINE-VERSION, MACHINE-INSTANCE and
  1587. SHORT-SITE-NAME, LONG-SITE-NAME should be defined by every user in his
  1588. site-specific CONFIG.LSP file.
  1589.  
  1590. The variable *FEATURES* initially contains the symbols
  1591.    CLISP            ; this implementation
  1592.    COMMON-LISP
  1593.    CLTL1
  1594.    INTERPRETER
  1595.    COMPILER
  1596.    LOGICAL-PATHNAMES
  1597.    FFI
  1598.    LOOP
  1599.    CLOS
  1600.    AMIGA            ; if hardware = Amiga and operating system = Exec/AmigaDOS
  1601.    DOS              ; if hardware = PC (clone) and operating system = DOS
  1602.    OS/2             ; if hardware = PC (clone) and operating system = OS/2
  1603.    PC386            ; if hardware = PC (clone) with a 386/486
  1604.    UNIX             ; if                            operating system = Unix
  1605.                     ;                               (yes, in this case the
  1606.                     ;                               hardware is irrelevant!)
  1607.  
  1608.  
  1609.                            CHAPTER 26: Loop
  1610.                            ----------------
  1611.  
  1612. The CLtL2 macros LOOP and LOOP-FINISH are implemented.
  1613.  
  1614.  
  1615.                        CHAPTER 27: Pretty Printing
  1616.                        ---------------------------
  1617.  
  1618. The CLtL2 macro FORMATTER is implemented.
  1619.  
  1620.  
  1621.                  CHAPTER 28: Common Lisp Object System
  1622.                  -------------------------------------
  1623.  
  1624. The CLOS symbols are exported from the package "CLOS" and thus normally
  1625. visible in all user packages. If you don't want them (for example, if you
  1626. want to use PCL instead of CLOS), do (UNUSE-PACKAGE "CLOS").
  1627.  
  1628. The functions
  1629.   SLOT-VALUE, SLOT-BOUNDP, SLOT-MAKUNBOUND, SLOT-EXISTS-P,
  1630.   FIND-CLASS, (SETF FIND-CLASS), CLASS-OF, CALL-NEXT-METHOD, NEXT-METHOD-P,
  1631.   CLASS-NAME, (SETF CLASS-NAME), NO-APPLICABLE-METHOD, NO-NEXT-METHOD,
  1632.   FIND-METHOD, ADD-METHOD, REMOVE-METHOD, COMPUTE-APPLICABLE-METHODS,
  1633.   METHOD-QUALIFIERS, FUNCTION-KEYWORDS, SLOT-MISSING, SLOT-UNBOUND,
  1634.   PRINT-OBJECT, DESCRIBE-OBJECT, MAKE-INSTANCE, INITIALIZE-INSTANCE,
  1635.   REINITIALIZE-INSTANCE, SHARED-INITIALIZE,
  1636. the macros
  1637.   WITH-SLOTS, WITH-ACCESSORS, DEFCLASS, DEFMETHOD, DEFGENERIC,
  1638.   GENERIC-FUNCTION, GENERIC-FLET, GENERIC-LABELS,
  1639. the classes
  1640.   STANDARD-CLASS, STRUCTURE-CLASS, BUILT-IN-CLASS, STANDARD-OBJECT,
  1641.   STANDARD-GENERIC-FUNCTION, STANDARD-METHOD and all predefined classes,
  1642. and the method combination
  1643.   STANDARD
  1644. are implemented.
  1645.  
  1646. Deviations from CLtL2 chapter 28:
  1647.  
  1648. DEFCLASS : It *is* required that the superclasses of a class be defined before
  1649. the DEFCLASS form for the class is evaluated.
  1650.  
  1651. DEFCLASS supports the option :METACLASS STRUCTURE-CLASS. This option is
  1652. necessary in order to define a subclass of a DEFSTRUCT-defined structure type
  1653. using DEFCLASS instead of DEFSTRUCT.
  1654.  
  1655. The REAL type is added to the predefined classes listed in table 28-1.
  1656.  
  1657. Only STANDARD method combination is implemented.
  1658.  
  1659. When CALL-NEXT-METHOD is called with arguments, the rule that the ordered
  1660. set of applicable methods must be the same as for the original arguments
  1661. is not enforced by the implementation.
  1662.  
  1663. CALL-NEXT-METHOD and NEXT-METHOD-P are local macros, not local functions.
  1664. Use #'(lambda () (call-next-method)) instead of #'call-next-method if you
  1665. really need it as a function.
  1666.  
  1667. There is a generic function NO-PRIMARY-METHOD (analogous to
  1668. NO-APPLICABLE-METHOD) which is called when a generic function of the class
  1669. STANDARD-GENERIC-FUNCTION is invoked and no primary method on that generic
  1670. function is applicable.
  1671.  
  1672. GENERIC-FLET and GENERIC-LABELS are implemented as macros, not as special
  1673. forms.
  1674.  
  1675. The function ENSURE-GENERIC-FUNCTION is not implemented.
  1676.  
  1677. ADD-METHOD can put methods into other generic functions than the one the method
  1678. came from.
  1679.  
  1680. PRINT-OBJECT and DESCRIBE-OBJECT are only called on objects of type
  1681. STANDARD-OBJECT.
  1682.  
  1683. DESCRIBE-OBJECT should not call DESCRIBE recursively as this would produce
  1684. more information than is likely to be useful to a human reader.
  1685.  
  1686. DOCUMENTATION still has the CLtL1 implementation.
  1687.  
  1688. User-defined method combination is not supported.
  1689. The sections 28.1.7.3., 28.1.7.4., the macros DEFINE-METHOD-COMBINATION,
  1690. CALL-METHOD and the functions INVALID-METHOD-ERROR, METHOD-COMBINATION-ERROR,
  1691. METHOD-QUALIFIERS are not implemented.
  1692.  
  1693. The special form WITH-ADDED-METHODS is not implemented.
  1694.  
  1695. Redefining classes is not supported.
  1696. The sections 28.1.10., 28.1.10.1., 28.1.10.2., 28.1.10.3., 28.1.10.4. and the
  1697. function UPDATE-INSTANCE-FOR-REDEFINED-CLASS are not implemented.
  1698.  
  1699. Changing the class of a given instance is not supported.
  1700. The sections 28.1.11., 28.1.11.1., 28.1.11.2., 28.1.11.3. and the functions
  1701. CHANGE-CLASS, UPDATE-INSTANCE-FOR-DIFFERENT-CLASS, MAKE-INSTANCES-OBSOLETE are
  1702. not implemented.
  1703.  
  1704.  
  1705.                         CHAPTER 29: Conditions
  1706.                         ----------------------
  1707.  
  1708. 29.4.1.
  1709. -------
  1710.  
  1711. The default condition type for conditions created by SIGNAL is
  1712. SIMPLE-CONDITION, not SIMPLE-ERROR.
  1713.  
  1714. 29.4.4.
  1715. -------
  1716.  
  1717. The macro (MUFFLE-CERRORS {form}*) executes the forms. When a continuable
  1718. error occurs, no message is printed. Instead, the CONTINUE restart is invoked.
  1719.  
  1720. The macro (APPEASE-CERRORS {form}*) executes the forms. When a continuable
  1721. error occurs, the error is printed as a warning and the CONTINUE restart is
  1722. invoked.
  1723.  
  1724. The macro (EXIT-ON-ERROR {form}*) executes the forms. When a non-continuable
  1725. error occurs, the error is printed and CLISP terminates with error status.
  1726.  
  1727. 29.4.7.
  1728. -------
  1729.  
  1730. In RESTART-CASE clauses the argument list can also be specified after the
  1731. keyword/value pairs instead of before them. The syntax therefore is
  1732.   (RESTART-CASE form {restart-clause}*)
  1733. with
  1734.   restart-clause ::=   (restart-name arglist {keyword value}* {form}*)
  1735.                      | (restart-name {keyword value}* arglist {form}*)
  1736.  
  1737. The macro WITH-RESTARTS is like RESTART-CASE, except that the forms are
  1738. specified after the restart clauses instead of before them, and the
  1739. restarts created are not implicitly associated to any condition.
  1740.   (WITH-RESTARTS ({restart-clause}*) {form}*)
  1741. is therefore equivalent to (RESTART-CASE (PROGN {form}*) {restart-clause}*).
  1742.  
  1743. 29.4.8.
  1744. -------
  1745.  
  1746. COMPUTE-RESTARTS and FIND-RESTART behave as specified in dpANS: If the
  1747. optional condition argument is not NIL, only restarts associated with that
  1748. condition and restarts associated to no condition at all are considered.
  1749. Therefore the effect of associating a restart to a condition is not to
  1750. activate it, but to hide it from other conditions. This makes the syntax
  1751. dependent implicit association performed by RESTART-CASE nearly obsolete.
  1752.  
  1753. 29.4.9.
  1754. -------
  1755.  
  1756. The default condition type for conditions created by WARN is SIMPLE-WARNING,
  1757. not SIMPLE-ERROR.
  1758.  
  1759.  
  1760.                CHAPTER 90: Platform independent Extensions
  1761.                -------------------------------------------
  1762.  
  1763. 90.1. Saving an Image
  1764. ---------------------
  1765.  
  1766. The function (SAVEINITMEM [filename [:quiet] [:init-function]]) saves the
  1767. running CLISP's memory to a file. The filename defaults to "lispinit.mem".
  1768. If the :QUIET argument is not NIL, the startup banner and the good-bye
  1769. message will be suppressed. The :INIT-FUNCTION argument specifies a function
  1770. that will be executed at startup of the saved image.
  1771.  
  1772. 90.2. Quitting Lisp
  1773. -------------------
  1774.  
  1775. The functions (EXIT [errorp]), (QUIT [errorp]) and (BYE [errorp])
  1776. - all synonymous - terminate CLISP. If errorp is not NIL, CLISP aborts with
  1777. error status, i.e. the environment is informed that the CLISP session didn't
  1778. succeed.
  1779.  
  1780. 90.3. The Language
  1781. ------------------
  1782.  
  1783. The language CLISP uses to communicate with the user can be either
  1784. ENGLISH or DEUTSCH (i.e. german) or FRANCAIS (i.e. french). The macros
  1785. ENGLISH, DEUTSCH, FRANCAIS and LANGUAGE-CASE produce code that depends on
  1786. the language:
  1787. (ENGLISH english-form DEUTSCH deutsch-form FRANCAIS francais-form)
  1788. - and all permutations of this - evaluates all of english-form, deutsch-form,
  1789. francais-form in no particular order and returns the evaluation result
  1790. corresponding to the user language.
  1791. (LANGUAGE-CASE {clause}*) executes the clause (analogous to CASE) that
  1792. corresponds to the user language.
  1793. The language itself is the value of
  1794. (ENGLISH 'ENGLISH DEUTSCH 'DEUTSCH FRANCAIS 'FRANCAIS).
  1795.  
  1796. 90.4. Finalization
  1797. ------------------
  1798.  
  1799. Calling (FINALIZE object function) has the effect that when the specified
  1800. object is being garbage collected, (FUNCALL function object) will be executed.
  1801.  
  1802. Calling (FINALIZE object function guardian) has a similar effect, but only
  1803. as long as the "guardian" has not been garbage collected: When object is
  1804. being garbage collected, (FUNCALL function object guardian) will be executed.
  1805. If the guardian is garbage collected before object is, nothing happens.
  1806.  
  1807. Note: The time when "object is being garbage collected" is not defined
  1808. deterministically. (Actually, it possibly never occurs.) It denotes a moment
  1809. at which no references to object exist from other Lisp objects. When the
  1810. function is called, object (and possibly guardian) enter the "arena of live
  1811. Lisp objects" again.
  1812.  
  1813. No finalization request will be executed more than once.
  1814.  
  1815.  
  1816.                   CHAPTER 91: The Debugger and Stepper
  1817.                   ------------------------------------
  1818.  
  1819. The debugger may be invoked through the functions INVOKE-DEBUGGER, BREAK,
  1820. SIGNAL, ERROR, CERROR, WARN. The stepper is invoked through the macro STEP.
  1821. Debugger and stepper execute subordinate READ - EVAL - PRINT loops (called
  1822. "break loops") which are analogous to the main READ - EVAL - PRINT loop except
  1823. for the prompt and the set of available commands. Commands must be typed
  1824. literally, without surrounding quotes or white space.
  1825.  
  1826. Commands common to the main loop, the debugger and the stepper:
  1827.   Help       prints a list of available commands.
  1828.  
  1829. Commands common to the debugger and the stepper:
  1830.   Abort      and
  1831.   Unwind     abort to the next most recent READ - EVAL - PRINT loop.
  1832.  
  1833. The stack is organized into frames and other stack elements. Usually every
  1834. invocation of an interpreted function and every evaluation of an interpreted
  1835. form corresponds to one stack frame. Special forms such as LET, LET*,
  1836. UNWIND-PROTECT and CATCH produce special kinds of stack frames.
  1837.  
  1838. In a break loop there is a current stack frame, which is initially the most
  1839. recent stack frame but can be moved using the debugger commands Up and Down.
  1840.  
  1841. Evaluation of forms in a break loop occurs in the lexical environment of the
  1842. current stack frame but in the dynamic environment of the debugger's caller.
  1843. This means that to inspect or modify a lexical variable all you have to do
  1844. is to move to the current stack frame just below the frame that corresponds
  1845. to the form or the function call that binds that variable.
  1846.  
  1847. There is a current "stack mode" which defines in how much detail the stack
  1848. is shown by the stack related debugger commands.
  1849.  
  1850. Commands common to the debugger and the stepper:
  1851.   Mode-1      sets the current mode to 1: all the stack elements are
  1852.               considered. This mode is fine for debugging compiled functions.
  1853.   Mode-2      sets the current mode to 2: all the frames are considered.
  1854.   Mode-3      sets the current mode to 3: only lexical frames (frames that
  1855.               correspond to special forms that modify the lexical environment)
  1856.               are considered.
  1857.   Mode-4      sets the current mode to 4 (the default): only EVAL and APPLY
  1858.               frames are considered. Every evaluation of a form in the
  1859.               interpreter corresponds to an EVAL frame.
  1860.   Mode-5      sets the current mode to 5: only APPLY frames are considered.
  1861.               Every invocation of an interpreted function corresponds to one
  1862.               APPLY frame.
  1863.   Where       shows the current stack frame.
  1864.   Up          goes up one frame, i.e. to the caller if in mode-5
  1865.   Down        does down one frame, i.e. to the callee if in mode-5
  1866.   Top         goes to top frame, i.e. to the top-level form if in mode-4
  1867.   Bottom      goes to bottom (most recent) frame, i.e. most probably to the
  1868.               form or function that caused the debugger to be entered.
  1869.   Backtrace   lists the stack in current mode, bottom frame first, top frame
  1870.               last.
  1871.   Backtrace-1 lists the stack in mode 1.
  1872.   Backtrace-2 lists the stack in mode 2.
  1873.   Backtrace-3 lists the stack in mode 3.
  1874.   Backtrace-4 lists the stack in mode 4.
  1875.   Backtrace-5 lists the stack in mode 5.
  1876. If the current stack frame is an EVAL or APPLY frame, the following commands
  1877. are available as well:
  1878.   Break+      sets a breakpoint in the current frame. When the corresponding
  1879.               form or function will be left, the debugger will be entered
  1880.               again, with the variable *TRACE-VALUES* containing a list of
  1881.               its values.
  1882.   Break-      removes a breakpoint from the current frame.
  1883.   Redo        re-evaluates the corresponding form or function call. This
  1884.               command can be used to restart parts of a computation without
  1885.               aborting it entirely.
  1886.   Return      leaves the current frame. You will be prompted for the
  1887.               return values.
  1888.  
  1889. Commands specific to the debugger:
  1890.   Continue    continues evaluation of the program.
  1891.  
  1892. Commands specific to the stepper:
  1893.   Step        step into a form: evaluate this form in single step mode
  1894.   Next        step over a form: evaluate this form at once
  1895.   Over        step over this level: evaluate at once up to the next return
  1896.   Continue    switch off single step mode, continue evaluation
  1897.  
  1898. The stepper is usually used like this: If some form returns a strange value
  1899. or results in an error, call  (STEP form)  and navigate using the commands
  1900. Step  and  Next  until you reach the form you regard as responsible. If you
  1901. are too fast (execute Next once and get the error), there is no way back; you
  1902. have to restart the entire stepper session. If you are too slow (stepped into
  1903. a function or a form which certainly is OK), a couple of Next commands or one
  1904. Over command will help.
  1905.  
  1906.  
  1907.                 CHAPTER 99: Platform specific Extensions
  1908.                 ----------------------------------------
  1909.  
  1910. 99.2. Random Screen Access
  1911. --------------------------
  1912.  
  1913. (SCREEN:MAKE-WINDOW)
  1914.   returns a "window stream". As long as this stream is open, the terminal
  1915.   is in cbreak/noecho mode. *TERMINAL-IO* shouldn't be used for input or
  1916.   output during this time. (Use WITH-KEYBOARD and *KEYBOARD-INPUT* instead.)
  1917.  
  1918. (SCREEN:WITH-WINDOW . body)
  1919.   binds SCREEN:*WINDOW* to a window stream and executes body. The stream is
  1920.   guaranteed to be closed when the body is left. During its execution,
  1921.   *TERMINAL-IO* shouldn't be used, as above.
  1922.  
  1923. (SCREEN:WINDOW-SIZE window-stream)
  1924.   returns the window's size, as two values:
  1925.   height (= Ymax+1) and width (= Xmax+1).
  1926.  
  1927. (SCREEN:WINDOW-CURSOR-POSITION window-stream)
  1928.   returns the position of the cursor in the window, as two values:
  1929.   line (>=0, <=Ymax, 0 means top), column (>=0, <=Xmax, 0 means left margin).
  1930.  
  1931. (SCREEN:SET-WINDOW-CURSOR-POSITION window-stream line column)
  1932.   sets the position of the cursor in the window.
  1933.  
  1934. (SCREEN:CLEAR-WINDOW window-stream)
  1935.   clears the window's contents and puts the cursor in the upper left corner.
  1936.  
  1937. (SCREEN:CLEAR-WINDOW-TO-EOT window-stream)
  1938.   clears the window's contents from the cursor position to the end of window.
  1939.  
  1940. (SCREEN:CLEAR-WINDOW-TO-EOL window-stream)
  1941.   clears the window's contents from the cursor position to the end of line.
  1942.  
  1943. (SCREEN:DELETE-WINDOW-LINE window-stream)
  1944.   removes the cursor's line, moves the lines below it up by one line and
  1945.   clears the window's last line.
  1946.  
  1947. (SCREEN:INSERT-WINDOW-LINE window-stream)
  1948.   inserts a line at the cursor's line, moving the lines below it down by
  1949.   one line.
  1950.  
  1951. (SCREEN:HIGHLIGHT-ON window-stream)
  1952.   switches highlighted output on.
  1953.  
  1954. (SCREEN:HIGHLIGHT-OFF window-stream)
  1955.   switches highlighted output off.
  1956.  
  1957. (SCREEN:WINDOW-CURSOR-ON window-stream)
  1958.   makes the cursor visible, a cursor block in most implementations.
  1959.  
  1960. (SCREEN:WINDOW-CURSOR-OFF window-stream)
  1961.   makes the cursor invisible, in implementations where this is possible.
  1962.  
  1963. 99.3. External Modules
  1964. ----------------------
  1965.  
  1966.                    Managing external modules for CLISP
  1967.                    ===================================
  1968.  
  1969. CLISP has a facility for adding external modules (written in C, for example).
  1970. It is invoked through clisp-link.
  1971.  
  1972. A module is a piece of external code which defines extra Lisp objects, symbols
  1973. and functions. A module name must consist of the characters A-Z,a-z,_,0-9. The
  1974. module name "clisp" is reserved. Normally a module name is derived from the
  1975. corresponding file name.
  1976.  
  1977. clisp-link needs a directory containing:
  1978.     modules.d
  1979.     modules.c
  1980.     module.cc
  1981.     clisp.h
  1982. clisp-link expects to find these files in a subdirectory linkkit/ of the
  1983. current directory. This can be overridden by the environment variable
  1984. CLISP_LINKKIT.
  1985.  
  1986. clisp-link operates on CLISP linking sets and on module sets.
  1987.  
  1988. A linking set is a directory containing:
  1989.     makevars          some /bin/sh commands, setting the variables
  1990.                         CC       the C compiler
  1991.                         CFLAGS   flags for the C compiler, when compiling
  1992.                         CLFLAGS  flags for the C compiler, when linking
  1993.                         LIBS     libraries to use when linking
  1994.                         X_LIBS   additional X window system libraries to use
  1995.                         RANLIB   the ranlib command
  1996.                         FILES    the list of files needed when linking
  1997.     modules.h         the list of modules contained in this linking set
  1998.     all the FILES listed in makevars
  1999.     lisp.run          the executable
  2000.     lispinit.mem      the memory image
  2001. To run a clisp contained in some linking set <dir>, call
  2002. "<dir>/lisp.run -M <dir>/lispinit.mem".
  2003.  
  2004. A module set is a directory containing:
  2005.     link.sh          some /bin/sh commands, which prepare the directory
  2006.                      before linking, and set the variables NEW_FILES, NEW_LIBS,
  2007.                      NEW_MODULES and TO_LOAD
  2008. and any other files needed by link.sh .
  2009. Note that in link.sh the module set directory is referred to as "$modulename"/.
  2010. The NEW_FILES variable shall contain a space-separated list of files that
  2011. belong to the module set and will belong to every new linking set. The NEW_LIBS
  2012. variable shall contain a space-separated list of files or C compiler switches
  2013. that need to be passed to the C compiler when linking the lisp.run belonging
  2014. to a new linking set. The NEW_MODULES variable shall contain a space-separated
  2015. list of the module names belonging to the module set. Normally, every .c file
  2016. in the module set defines a module of its own. The module name is derived from
  2017. the file name. The TO_LOAD variable shall contain a space-separated list of
  2018. Lisp files to load before building the lispinit.mem belonging to a new linking
  2019. set.
  2020.  
  2021. The command
  2022. "clisp-link create-module-set <module-dir> <file1.c> ..."
  2023. creates a module set in <module-dir> which refers (via symbolic links) to
  2024. file1.c etc. The files are expected to be modules of their own.
  2025.  
  2026. The command
  2027. "clisp-link add-module-set <module-dir> <source-dir> <destination-dir>"
  2028. combines a linking set in <source-dir> and a module in <module-dir> to a new
  2029. linking set, in a directory <destination-dir> which is newly created.
  2030.  
  2031.                               Example
  2032.                               -------
  2033.  
  2034. To link in the FFI bindings for the Linux operating system, the following
  2035. steps are needed. (Step 1 and step 2 need not be executed in this order.)
  2036.  
  2037. 1. Create a new module set:
  2038.  
  2039.    $ clisp-link create-module-set linux /somewhere/bindings/linux.c
  2040.  
  2041.    Modify the newly created linux/link.sh to add "-lm" to the libraries:
  2042.  
  2043.    NEW_LIBS="$file_list"
  2044.    -->
  2045.    NEW_LIBS="$file_list -lm"
  2046.  
  2047.    Modify the newly created linux/link.sh to load linux.fas before saving
  2048.    the memory image:
  2049.  
  2050.    TO_LOAD=''
  2051.    -->
  2052.    TO_LOAD='/somewhere/bindings/linux.fas'
  2053.  
  2054. 2. Compile linux.lsp, creating linux.c:
  2055.  
  2056.    $ clisp -c /somewhere/bindings/linux.lsp
  2057.  
  2058. 3. Create a new linking set:
  2059.  
  2060.    $ clisp-link add-module-set linux base base+linux
  2061.  
  2062. 4. Run and try it:
  2063.  
  2064.    $ base+linux/lisp.run -M base+linux/lispinit.mem
  2065.    > (linux::stat "/tmp")
  2066.  
  2067. 99.4. The Foreign Function Call Facility
  2068. ----------------------------------------
  2069.  
  2070.                  The Foreign Function Call Facility
  2071.                  ==================================
  2072.  
  2073. A foreign function description is written as a Lisp file,
  2074. and when compiled it produces a .c file which is then compiled
  2075. by the C compiler and may be linked together with lisp.a.
  2076.  
  2077. All symbols relating to the foreign function interface are exported from
  2078. the package FFI. To use them, (USE-PACKAGE "FFI").
  2079.  
  2080. Special FFI forms may appear anywhere in the Lisp file.
  2081.  
  2082.                                 Overview
  2083.                                 --------
  2084.  
  2085. These are the special FFI forms. We have taken a pragmatic approach:
  2086. the only foreign languages we support for now are C and ANSI C.
  2087.  
  2088. (DEF-C-TYPE name <c-type>)
  2089.  
  2090. (DEF-C-VAR name {option}*)
  2091.   option ::=
  2092.       (:name <c-name>)
  2093.     | (:type <c-type>)
  2094.     | (:read-only <boolean>)
  2095.     | (:alloc <allocation>)
  2096.  
  2097. (DEF-CALL-OUT name {option}*)
  2098.   option ::=
  2099.       (:name <c-name>)
  2100.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2101.     | (:return-type <c-type> [<allocation>])
  2102.     | (:language <language>)
  2103.  
  2104. (DEF-CALL-IN name {option}*)
  2105.   option ::=
  2106.       (:name <c-name>)
  2107.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2108.     | (:return-type <c-type> [<allocation>])
  2109.     | (:language <language>)
  2110.  
  2111. (DEF-C-CALL-OUT name {option}*)
  2112.   option ::=
  2113.       (:name <c-name>)
  2114.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2115.     | (:return-type <c-type> [<allocation>])
  2116.  
  2117. (DEF-C-CALL-IN name {option}*)
  2118.   option ::=
  2119.       (:name <c-name>)
  2120.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2121.     | (:return-type <c-type> [<allocation>])
  2122.  
  2123. (DEF-C-STRUCT name (<ident> <c-type>)*)
  2124.  
  2125. (DEF-C-ENUM name {<ident> | (<ident> [<value>])}*)
  2126.  
  2127. (C-LINES format-string {argument}*)
  2128.  
  2129. (ELEMENT c-place {index}*)
  2130. (DEREF c-place)
  2131. (SLOT c-place slot-name)
  2132. (CAST c-place <c-type>)
  2133.  
  2134. (TYPEOF c-place)
  2135. (SIZEOF c-place), (SIZEOF <c-type>)
  2136. (BITSIZEOF c-place), (BITSIZEOF <c-type>)
  2137.  
  2138. (VALIDP foreign-entity)
  2139.  
  2140. name is any Lisp symbol.
  2141.  
  2142. <c-name> is a string.
  2143.  
  2144.                        (Foreign) C types
  2145.                        -----------------
  2146.  
  2147. Foreign C types are used in the FFI. They are *not* regular Common Lisp
  2148. types or CLOS classes.
  2149.  
  2150. A <c-type> is either a predefined C type or the name of a type defined by
  2151. DEF-C-TYPE.
  2152.  
  2153. The simple C types are these:
  2154.  
  2155.  Lisp name     Lisp equiv           C equiv        ILU equiv
  2156.   nil           NIL                  void                             (o)
  2157.   boolean       (MEMBER NIL T)       int            BOOLEAN
  2158.   character     STRING-CHAR          char           SHORT CHARACTER
  2159.   char          INTEGER              signed char
  2160.   uchar         INTEGER              unsigned char
  2161.   short         INTEGER              short
  2162.   ushort        INTEGER              unsigned short
  2163.   int           INTEGER              int
  2164.   uint          INTEGER              unsigned int
  2165.   long          INTEGER              long
  2166.   ulong         INTEGER              unsigned long
  2167.   uint8         (UNSIGNED-BYTE 8)    uint8          BYTE
  2168.   sint8         (SIGNED-BYTE 8)      sint8
  2169.   uint16        (UNSIGNED-BYTE 16)   uint16         SHORT CARDINAL
  2170.   sint16        (SIGNED-BYTE 16)     sint16         SHORT INTEGER
  2171.   uint32        (UNSIGNED-BYTE 32)   uint32         CARDINAL
  2172.   sint32        (SIGNED-BYTE 32)     sint32         INTEGER
  2173.   uint64        (UNSIGNED-BYTE 64)   uint64         LONG CARDINAL     (*)
  2174.   sint64        (SIGNED-BYTE 64)     sint64         LONG INTEGER      (*)
  2175.   single-float  SINGLE-FLOAT         float
  2176.   double-float  DOUBLE-FLOAT         double
  2177. (o) as a result type only.
  2178. (*) does not work on all platforms.
  2179.  
  2180. The predefined C types are:
  2181.  
  2182.   c-type ::=
  2183.       <simple-c-type>
  2184.     | C-POINTER
  2185.     | C-STRING
  2186.     | (C-STRUCT <class> (<ident> <c-type>)*)
  2187.     | (C-UNION (<ident> <c-type>)*)
  2188.     | (C-ARRAY <c-type> dimensions)
  2189.         dimensions ::= number | ({number}*)
  2190.     | (C-ARRAY-MAX <c-type> maxdimension)
  2191.         maxdimension ::= number
  2192.     | (C-FUNCTION {option}*)
  2193.         option ::=
  2194.             (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2195.           | (:return-type <c-type> [<allocation>])
  2196.           | (:language <language>)
  2197.     | (C-PTR <c-type>)
  2198.     | (C-PTR-NULL <c-type>)
  2199.     | (C-ARRAY-PTR <c-type>)
  2200.  
  2201. (DEF-C-TYPE name <c-type>)
  2202. makes name a shortcut for <c-type>. Note that <c-type> may already refer
  2203. to name. Forward declarations of types are not possible, however.
  2204.  
  2205. The type C-POINTER corresponds to what C calls "void*", an opaque pointer.
  2206.  
  2207. The type C-STRING corresponds to what C calls "char*", a zero-terminated
  2208. string. Its Lisp equivalent is a string, without the trailing zero character.
  2209.  
  2210. The type (C-STRUCT class (ident1 type1) ... (ident2 type2)) is equivalent to
  2211. what C calls "struct { type1 ident1; ...; type2 ident2; }". Its Lisp
  2212. equivalent is: if class is VECTOR, a simple-vector; if class is LIST, a list;
  2213. if class is a symbol naming a structure or CLOS class: an instance of this
  2214. class, with slots of names ident1,...,ident2.
  2215.  
  2216. The type (C-UNION (ident1 type1) ... (ident2 type2)) is equivalent to what C
  2217. calls "union { type1 ident1; ...; type2 ident2; }". Conversion to and from
  2218. Lisp assumes that a value is to be viewed as being of type1.
  2219.  
  2220. The type (C-ARRAY type dim1 ... dim2) is equivalent to what C calls
  2221. "type [dim1]...[dim2]". Note that when an array is passed as an argument to
  2222. a function in C, it is actually passed as a pointer; you therefore have to
  2223. write (C-PTR (C-ARRAY ...)) for this argument's type.
  2224.  
  2225. The type (C-ARRAY-MAX type maxdim) is equivalent to what C calls
  2226. "type [maxdim]", an array containing up to maxdim elements. The array is
  2227. zero-terminated if it contains less than maxdim elements. Conversion from Lisp
  2228. of an array with more than maxdim elements silently ignores the superfluous
  2229. elements.
  2230.  
  2231. The type (C-PTR type) is equivalent to what C calls "type *": a pointer to
  2232. a single item of the given type.
  2233.  
  2234. The type (C-PTR-NULL type) is also equivalent to what C calls "type *": a
  2235. pointer to a single item of the given type, with the exception that C NULL
  2236. corresponds to Lisp NIL.
  2237.  
  2238. The type (C-ARRAY-PTR type) is equivalent to what C calls "type (*)[]":
  2239. a pointer to a zero-terminated array of items of the given type.
  2240.  
  2241. The type (C-FUNCTION (:return-type rtype) (:arguments (arg1 type1 ...) ...))
  2242. designates a C function that can be called according to the given prototype
  2243. (rtype (*) (type1, ...)).
  2244. The <language> is either :C (denotes K&R C) or :STDC (denotes ANSI C). It
  2245. specifies whether the C function has been compiled by a K&R C compiler or by
  2246. an ANSI C compiler.
  2247. Conversion between C functions and Lisp functions is transparent.
  2248.  
  2249. (DEF-C-STRUCT <name> (<ident> <c-type>)*) defines <name> to be both a
  2250. DEFSTRUCT structure type and a foreign C type with the given slots.
  2251.  
  2252. (DEF-C-ENUM <name> {<ident> | (<ident> [<value>])}*) defines <ident>s as
  2253. constants, similarly to the C declaration  enum { <ident> [= <value>], ... };
  2254.  
  2255. (C-LINES format-string {argument}*)
  2256. outputs the string (FORMAT nil format-string {argument}*) to the C output
  2257. file. This is a rarely needed low-level facility.
  2258.  
  2259. The form (SIZEOF <c-type>) returns the size and alignment of a C type,
  2260. measured in bytes.
  2261.  
  2262. The form (BITSIZEOF <c-type>) returns the size and alignment of a C type,
  2263. measured in bits.
  2264.  
  2265. The predicate (VALIDP foreign-entity) returns NIL if the foreign-entity
  2266. (e.g. the Lisp equivalent of a C-POINTER) refers to a pointer which is
  2267. invalid because it comes from a previous Lisp session. It returns T if
  2268. foreign-entity can be used within the current Lisp process.
  2269.  
  2270.                        Foreign variables
  2271.                        -----------------
  2272.  
  2273. Foreign variables are variables whose storage is allocated in the foreign
  2274. language module. They can nevertheless be evaluated and modified through SETQ,
  2275. just as normal variables can, except that the range of allowed values is
  2276. limited according to the variable's foreign type. Note that for a foreign
  2277. variable X the form (EQL X X) is not necessarily true, since every time X is
  2278. evaluated its foreign value is converted to a freshly created Lisp value.
  2279.  
  2280. (DEF-C-VAR name {option}*)
  2281.   option ::=
  2282.       (:name <c-name>)
  2283.     | (:type <c-type>)
  2284.     | (:read-only <boolean>)
  2285.     | (:alloc <allocation>)
  2286.  
  2287. defines a foreign variable. `name' is the Lisp name, a regular Lisp symbol.
  2288.  
  2289. The :name option specifies the name, as seen from C, as a string. If not
  2290. specified, it is derived from the print name of the Lisp name.
  2291.  
  2292. The :type option specifies the variable's foreign type.
  2293.  
  2294. If the :read-only option is specified and non-NIL, it will be impossible
  2295. to change the variable's value from within Lisp (using SETQ or similar).
  2296.  
  2297. The :alloc option can be either :NONE or :MALLOC-FREE and defaults to :NONE.
  2298. If it is :MALLOC-FREE, any values of type C-STRING, (C-PTR ...),
  2299. (C-PTR-NULL ...), (C-ARRAY-PTR ...) within the foreign value are assumed to
  2300. be pointers to malloc()-allocated storage, and when SETQ replaces an old
  2301. value by a new one, the old storage is freed using free() and the new storage
  2302. allocated using malloc(). If it is :NONE, SETQ assumes that the pointers
  2303. point to good storage (not NULL!) and overwrites the old values by the new
  2304. ones. This is dangerous (just think of overwriting a string with a longer one
  2305. or storing some data in a NULL pointer...) and deprecated.
  2306.  
  2307.                    Operations on foreign places
  2308.                    ----------------------------
  2309.  
  2310. A foreign variable `name' defined by DEF-C-VAR defines a "place", i.e.
  2311. a form which can also be used as argument to SETF. (An "lvalue" in C
  2312. terminology.) The following operations are available on foreign places:
  2313.  
  2314. (ELEMENT place index1 ... indexn)
  2315. Array element: If place is of foreign type (C-ARRAY <c-type> dim1 ... dimn)
  2316. and 0 <= index1 < dim1, ..., 0 <= indexn < dimn, this will be the place
  2317. corresponding to (aref place index1 ... indexn) or place[index1]...[indexn].
  2318. It is a place of type <c-type>.
  2319. If place is of foreign type (C-ARRAY-MAX <c-type> dim) and 0 <= index < dim,
  2320. this will be the place corresponding to (aref place index) or place[index].
  2321. It is a place of type <c-type>.
  2322.  
  2323. (DEREF place)
  2324. Dereference pointer: If place is of foreign type (C-PTR <c-type>) or
  2325. (C-PTR-NULL <c-type>), this will be the place the pointer points to. It is a
  2326. place of type <c-type>. For (C-PTR-NULL <c-type>), the place may not be NULL.
  2327.  
  2328. (SLOT place slot-name)
  2329. Struct or union component: If place is of foreign type
  2330. (C-STRUCT <class> ... (slot-name <c-type>) ...) or of type
  2331. (C-UNION ... (slot-name <c-type>) ...), this will be of type <c-type>.
  2332.  
  2333. (CAST place <c-type>)
  2334. Type change: A place denoting the same memory locations as the original place,
  2335. but of type <c-type>.
  2336.  
  2337. (TYPEOF place)
  2338. returns the <c-type> corresponding to the place.
  2339.  
  2340. (SIZEOF place) returns the size and alignment of the C type of place,
  2341. measured in bytes.
  2342.  
  2343. (BITSIZEOF place) returns the size and alignment of the C type of place,
  2344. measured in bits.
  2345.  
  2346.                        Foreign functions
  2347.                        -----------------
  2348.  
  2349. Foreign functions are functions which are defined in the foreign language.
  2350. There are named foreign functions (imported via DEF-CALL-OUT or created via
  2351. DEF-CALL-IN) and anonymous foreign functions; they arise through conversion
  2352. of function pointers.
  2353.  
  2354. A "call-out" function is a foreign function called from Lisp: control flow
  2355. temporarily leaves Lisp.
  2356. A "call-in" function is a Lisp function called from the foreign language:
  2357. control flow temporary enters Lisp.
  2358.  
  2359. (DEF-CALL-OUT name {option}*)
  2360.   option ::=
  2361.       (:name <c-name>)
  2362.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2363.     | (:return-type <c-type> [<allocation>])
  2364.     | (:language <language>)
  2365.  
  2366. defines a named call-out function. Any Lisp function call to #'name is
  2367. redirected to call the C function <c-name>.
  2368.  
  2369. DEF-C-CALL-OUT is equivalent to DEF-CALL-OUT with :LANGUAGE :C.
  2370.  
  2371. (DEF-CALL-IN name {option}*)
  2372.   option ::=
  2373.       (:name <c-name>)
  2374.     | (:arguments {(arg-name <c-type> [<param-mode> [<allocation>]])}*)
  2375.     | (:return-type <c-type> [<allocation>])
  2376.     | (:language <language>)
  2377.  
  2378. defines a named call-in function. Any C function call to the C function
  2379. <c-name> is redirected to call the Lisp function #'name.
  2380.  
  2381. DEF-C-CALL-IN is equivalent to DEF-CALL-IN with :LANGUAGE :C.
  2382.  
  2383.               Argument and result passing conventions
  2384.               ---------------------------------------
  2385.  
  2386. When passed to and from functions, allocation of arguments and results is
  2387. handled as follows:
  2388.  
  2389. Values of <simple-c-type>, C-POINTER are passed on the stack, with dynamic
  2390. extent. The <allocation> is effectively ignored.
  2391.  
  2392. Values of type C-STRING, (C-PTR ...), (C-PTR-NULL ...), (C-ARRAY-PTR ...) need
  2393. storage. The <allocation> specifies the allocation policy:
  2394.   <allocation> is :NONE          means that no storage is allocated.
  2395.   <allocation> is :ALLOCA        means allocation of storage on the stack,
  2396.                                        which has dynamic extent.
  2397.   <allocation> is :MALLOC-FREE   means that storage will be allocated
  2398.                                        via malloc() and freed via free().
  2399. If no <allocation> is specified, the default <allocation> is :NONE for most
  2400. types, but :ALLOCA for C-STRING and (C-PTR ...) and (C-PTR-NULL ...) and
  2401. (C-ARRAY-PTR ...) and for :OUT arguments. [Subject to change!]
  2402. The :MALLOC-FREE policy provides the ability to pass arbitrarily nested
  2403. structs containing pointers pointing to structs ... within a single conversion.
  2404.  
  2405. For call-out functions:
  2406.   For arguments passed from Lisp to C:
  2407.     If <allocation> is :MALLOC-FREE,
  2408.        Lisp allocates the storage using malloc() and never deallocates it.
  2409.        The C function is supposed to call free() when done with it.
  2410.     If <allocation> is :ALLOCA,
  2411.        Lisp allocates the storage on the stack, with dynamic extent. It is
  2412.        freed when the C function returns.
  2413.     If <allocation> is :NONE,
  2414.        Lisp assumes that the pointer already points to a valid area of the
  2415.        proper size and puts the result value there. This is dangerous! and
  2416.        deprecated.
  2417.   For results passed from C to Lisp:
  2418.     If <allocation> is :MALLOC-FREE,
  2419.        Lisp calls free() on it when done.
  2420.     If <allocation> is :NONE,
  2421.        Lisp does nothing.
  2422. For call-in functions:
  2423.   For arguments passed from C to Lisp:
  2424.     If <allocation> is :MALLOC-FREE,
  2425.        Lisp calls free() on it when done.
  2426.     If <allocation> is :ALLOCA or :NONE,
  2427.        Lisp does nothing.
  2428.   For results passed from Lisp to C:
  2429.     If <allocation> is :MALLOC-FREE,
  2430.        Lisp allocates the storage using malloc() and never deallocates it.
  2431.        The C function is supposed to call free() when done with it.
  2432.     If <allocation> is :NONE,
  2433.        Lisp assumes that the pointer already points to a valid area of the
  2434.        proper size and puts the result value there. This is dangerous! and
  2435.        deprecated.
  2436.  
  2437. A function parameter's <param-mode> may be
  2438. either :IN (means: read-only):
  2439.        The caller passes information to the callee.
  2440. or     :OUT (means: write-only):
  2441.        The callee passes information back to the caller on return.
  2442.        When viewed as a Lisp function, there is no Lisp argument corresponding
  2443.        to this, instead it means an additional return value.
  2444. or     :IN-OUT (means: read-write):
  2445.        Information is passed from the caller to the callee and then back to
  2446.        the caller. When viewed as a Lisp function, the ":OUT" value is
  2447.        returned as an additional multiple value.
  2448. The default is :IN.
  2449.  
  2450. [Currently, only :IN is fully implemented. :OUT works only with
  2451. <allocation> = :ALLOCA.]
  2452.  
  2453. On AmigaOS, <allocation> may not be :MALLOC-FREE because there is no commonly
  2454. used malloc()/free() library function.
  2455.  
  2456. On AmigaOS, the <allocation> may be followed by a register specification,
  2457. any of the symbols :D0, :D1, :D2, :D3, :D4, :D5, :D6, :D7, :A0, :A1, :A2,
  2458. :A3, :A4, :A5, :A6, each representing one 680x0 register. This works only
  2459. for integral types: integers, pointers, C-STRING, C-FUNCTION.
  2460.  
  2461. Passing C-STRUCT, C-UNION, C-ARRAY, C-ARRAY-MAX values as arguments (not via
  2462. pointers) is only possible to the extent the C compiler supports it. Most C
  2463. compilers do it right, but some C compilers (such as gcc on hppa) have
  2464. problems with this.
  2465.  
  2466.                            Examples
  2467.                            --------
  2468.  
  2469. Ex. 1: The C declaration
  2470.  
  2471.        struct foo {
  2472.            int a;
  2473.            struct foo * b[100];
  2474.        };
  2475.  
  2476. corresponds to
  2477.  
  2478.        (def-c-struct foo
  2479.          (a int)
  2480.          (b (c-array (c-ptr foo) 100))
  2481.        )
  2482.  
  2483. The element access
  2484.  
  2485.        struct foo f;
  2486.        f.b[7].a
  2487.  
  2488. corresponds to
  2489.  
  2490.        (declare (type foo f))
  2491.        (foo-a (aref (foo-b f) 7)) or (slot-value (aref (slot-value f 'b) 7) 'a)
  2492.  
  2493. Ex. 2: Here is an example of an external C variable and some accesses:
  2494.  
  2495.        struct bar {
  2496.            short x, y;
  2497.            char a, b;
  2498.            int z;
  2499.            struct bar * n;
  2500.        };
  2501.  
  2502.        extern struct bar * my_struct;
  2503.  
  2504.        my_struct->x++;
  2505.        my_struct->a = 5;
  2506.        my_struct = my_struct->n;
  2507.  
  2508. corresponds to
  2509.  
  2510.        (def-c-struct bar
  2511.          (x short)
  2512.          (y short)
  2513.          (a char)
  2514.          (b char) ; or (b character) if it represents a character, not a number
  2515.          (z int)
  2516.          (n (c-ptr bar))
  2517.        )
  2518.  
  2519.        (def-c-var my_struct (:type (c-ptr bar)))
  2520.  
  2521.        (setq my_struct (let ((s my_struct)) (incf (slot-value s 'x)) s))
  2522.        or (incf (slot my_struct 'x))
  2523.        (setq my_struct (let ((s my_struct)) (setf (slot-value s 'a) 5) s))
  2524.        or (setf (slot my_struct 'a) 5)
  2525.        (setq my_struct (slot-value my_struct 'n))
  2526.        or (setq my_struct (deref (slot my_struct 'n)))
  2527.  
  2528. Ex. 3: An example for calling an external function:
  2529. On ANSI C systems, <stdlib.h> contains the declarations
  2530.  
  2531.        typedef struct {
  2532.          int quot;   /* Quotient */
  2533.          int rem;    /* Remainder */
  2534.        } div_t;
  2535.        extern div_t div (int numer, int denom);
  2536.  
  2537. This translates to
  2538.  
  2539.        (def-c-struct div_t
  2540.          (quot int)
  2541.          (rem int)
  2542.        )
  2543.        (def-c-call-out div (:arguments (numer int) (denom int))
  2544.                            (:return-type div_t)
  2545.        )
  2546.  
  2547. Sample call from within Lisp:
  2548.  
  2549.        > (div 20 3)
  2550.        #S(DIV :QUOT 6 :REM 2)
  2551.  
  2552. Ex. 4: Another example for calling an external function:
  2553.  
  2554. Suppose the following is defined in a file "cfun.c":
  2555.  
  2556.        struct cfunr { int x; char *s; };
  2557.        struct cfunr * cfun (i,s,r,a)
  2558.            int i;
  2559.            char *s;
  2560.            struct cfunr * r;
  2561.            int a[10];
  2562.        {
  2563.            int j;
  2564.            struct cfunr * r2;
  2565.            printf("i = %d\n", i);
  2566.            printf("s = %s\n", s);
  2567.            printf("r->x = %d\n", r->x);
  2568.            printf("r->s = %s\n", r->s);
  2569.            for (j = 0; j < 10; j++) printf("a[%d] = %d.\n", j, a[j]);
  2570.            r2 = (struct cfunr *) malloc (sizeof (struct cfunr));
  2571.            r2->x = i+5;
  2572.            r2->s = "A C string";
  2573.            return r2;
  2574.        }
  2575.  
  2576. It is possible to call this function from Lisp using the file "callcfun.lsp"
  2577. (don't call it "cfun.lsp" - COMPILE-FILE would overwrite "cfun.c") whose
  2578. contents is:
  2579.  
  2580.        (in-package "TEST-C-CALL" :use '("LISP" "FFI"))
  2581.        (def-c-struct cfunr (x int) (s c-string))
  2582.        (def-c-call-out cfun (:arguments (i int)
  2583.                                         (s c-string)
  2584.                                         (r (c-ptr cfunr) :in :alloca)
  2585.                                         (a (c-ptr (c-array int 10)) :in :alloca)
  2586.                             )
  2587.                             (:return-type (c-ptr cfunr))
  2588.        )
  2589.        (defun call-cfun ()
  2590.          (cfun 5 "A Lisp string" (make-cfunr :x 10 :s "Another Lisp string")
  2591.                '#(0 1 2 3 4 5 6 7 8 9)
  2592.        ) )
  2593.  
  2594. Use the module facility:
  2595.  
  2596.        $ clisp-link create-module-set cfun callcfun.c
  2597.        $ cc -O -c cfun.c
  2598.        $ cd cfun
  2599.        $ ln -s ../cfun.o cfun.o
  2600.        Add cfun.o to NEW_LIBS and NEW_FILES in link.sh.
  2601.        $ cd ..
  2602.        $ base/lisp.run -M base/lispinit.mem -c callcfun.lsp
  2603.        $ clisp-link add-module-set cfun base base+cfun
  2604.        $ base+cfun/lisp.run -M base+cfun/lispinit.mem -i callcfun
  2605.        > (test-c-call::call-cfun)
  2606.        i = 5
  2607.        s = A Lisp string
  2608.        r->x = 10
  2609.        r->s = Another Lisp string
  2610.        a[0] = 0.
  2611.        a[1] = 1.
  2612.        a[2] = 2.
  2613.        a[3] = 3.
  2614.        a[4] = 4.
  2615.        a[5] = 5.
  2616.        a[6] = 6.
  2617.        a[7] = 7.
  2618.        a[8] = 8.
  2619.        a[9] = 9.
  2620.        #S(TEST-C-CALL::CFUNR :X 10 :S "A C string")
  2621.        > 
  2622.        $ rm -r base+cfun
  2623.  
  2624. Note that there is a memory leak here: The return value r2 of cfun() is
  2625. malloc()ed but never free()d. Specifying
  2626.        (:return-type (c-ptr cfunr) :malloc-free)
  2627. is not an alternative because this would also free(r2->x) but r2->x is a
  2628. pointer to static data.
  2629.  
  2630. Ex. 5: To sort an array of double-floats using the Lisp function SORT
  2631. instead of the C library function qsort(), one can use the following
  2632. interface code "sort1.c". The main problem is to pass a variable-sized array.
  2633.  
  2634.        extern void lispsort_begin (int);
  2635.        void* lispsort_function;
  2636.        void lispsort_double (int n, double * array)
  2637.        {
  2638.            double * sorted_array;
  2639.            int i;
  2640.            lispsort_begin(n); /* store #'sort2 in lispsort_function */
  2641.            sorted_array = ((double * (*) (double *)) lispsort_function) (array);
  2642.            for (i = 0; i < n; i++) array[i] = sorted_array[i];
  2643.            free(sorted_array);
  2644.        }
  2645.  
  2646. This is accompanied by "sort2.lsp":
  2647.  
  2648.        (use-package "FFI")
  2649.        (def-call-in lispsort_begin (:arguments (n int))
  2650.                                    (:return-type nil)
  2651.                                    (:language :stdc)
  2652.        )
  2653.        (def-c-var lispsort_function (:type c-pointer))
  2654.        (defun lispsort_begin (n)
  2655.          (setf (cast lispsort_function
  2656.                      `(c-function
  2657.                         (:arguments (v (c-ptr (c-array double-float ,n))))
  2658.                         (:return-type (c-ptr (c-array double-float ,n))
  2659.                                       :malloc-free
  2660.                       ) )
  2661.                )
  2662.                #'sort2
  2663.        ) )
  2664.        (defun sort2 (v)
  2665.          (declare (type vector v))
  2666.          (sort v #'<)
  2667.        )
  2668.  
  2669. To test this, use the following test file "sorttest.lsp":
  2670.  
  2671.        (def-call-out sort10
  2672.                      (:name "lispsort_double")
  2673.                      (:language :stdc)
  2674.                      (:arguments (n int)
  2675.                                  (array (c-ptr (c-array double-float 10))
  2676.                                         :in-out
  2677.        )             )           )
  2678.  
  2679. Now try
  2680.  
  2681.        $ clisp-link create-module-set sort sort2.c sorttest.c
  2682.        $ cc -O -c sort1.c
  2683.        $ cd sort
  2684.        $ ln -s ../sort1.o sort1.o
  2685.        Add sort1.o to NEW_LIBS and NEW_FILES in link.sh.
  2686.        $ cd ..
  2687.        $ base/lisp.run -M base/lispinit.mem -c sort2.lsp sorttest.lsp
  2688.        $ clisp-link add-module-set sort base base+sort
  2689.        $ base+sort/lisp.run -M base+sort/lispinit.mem -i sort2 sorttest
  2690.        > (sort10 10 '#(0.501d0 0.528d0 0.615d0 0.550d0 0.711d0
  2691.                        0.523d0 0.585d0 0.670d0 0.271d0 0.063d0))
  2692.        #(0.063d0 0.271d0 0.501d0 0.523d0 0.528d0 0.55d0 0.585d0 0.615d0 0.67d0 0.711d0)
  2693.        $ rm -r base+sort
  2694.  
  2695. 99.6. Graphics
  2696. --------------
  2697.  
  2698. Graphics primitives in CLISP
  2699. ============================
  2700.  
  2701. In CLISP 1994-01-07 or newer,
  2702. * DOS version,
  2703. * Linux version, installed setuid root,
  2704. there are some pixel graphics primitives in the SYSTEM package.
  2705. They operate on a VGA card.
  2706.  
  2707. Similar pixel graphics primitives can be used in the
  2708. * Unix version running under X11
  2709. by use of the small XTERM package available on
  2710. ma2s2.mathematik.uni-karlsruhe.de.
  2711.  
  2712. This is the description of the PC/VGA graphics primitives:
  2713.  
  2714. (SYSTEM::GRAPH-INIT [width [height [colors]]])
  2715. initializes the graphics system. The width, height parameters are hints for
  2716. the size of the desired graphics screen (positive integers). The colors
  2717. parameter is a hint for the number of colors. The actual width, height
  2718. is implementation dependent, currently up to 640x480 on VGA cards and up to
  2719. 1024x768 on ET4000 SVGA cards.
  2720. Returns an alist ((color-value color-keyword) ...) which lists the available
  2721. colours and their numerical equivalents.
  2722.  
  2723. (SYSTEM::GRAPH-SHOW)
  2724. switches the graphics hardware so that the graphics screen is visible. The
  2725. text screen is activated on any text output.
  2726.  
  2727. (SYSTEM::GRAPH-CLEAR [color])
  2728. fills the entire graphics screen with a single color.
  2729.  
  2730. (SYSTEM::GRAPH-DIMS)
  2731. returns two values: the actual width and the actual height of the graphics
  2732. screen (in pixels).
  2733.  
  2734. If (SYSTEM::GRAPH-DIMS) returns the values w and h, then valid screen
  2735. coordinates are pairs (x,y) with 0 <= x < w and 0 <= y < h. x=0 denotes the
  2736. left edge, y=0 the top edge.
  2737.  
  2738. (SYSTEM::GRAPH-DOT x y)
  2739. returns the colour of the pixel (x,y).
  2740. (SYSTEM::GRAPH-DOT x y color)
  2741. sets the colour of the pixel (x,y) to color.
  2742.  
  2743. (SYSTEM::GRAPH-BOX x1 y1 x2 y2 color)
  2744. draws a box (= filled rectangle) in colour color, the vertices being the pixels
  2745.         (x1,y1)   (x2,y1)
  2746.         (x1,y2)   (x2,y2)
  2747.  
  2748. (SYSTEM::GRAPH-LINE x1 y1 x2 y2 color)
  2749. Draws a line in colour color from pixel (x1,y1) to pixel (x2,y2).
  2750.  
  2751. (SYSTEM::GRAPH-TEXT x y dir string color)
  2752. Paints the text contained in string, starting at (x,y), in colour color,
  2753. and returns as values the end coordinates (x,y). dir is the direction:
  2754. 0 goes to the right, 90 vertically up, 180 to the left, 270 vertically down.
  2755.  
  2756. This specification is subject to change.
  2757.  
  2758. 99.7 Socket Streams
  2759. -------------------
  2760.  
  2761. (SOCKET-SERVER [port])
  2762.  
  2763. This function creates a socket, and binds a port the socket, and then
  2764. listens for connect attempts.  The server exists to watch for client 
  2765. connect attempts.
  2766.  
  2767. (SOCKET-SERVER-CLOSE socket-server)
  2768.  
  2769. Closes down the server socket.
  2770.  
  2771. (SOCKET-SERVER-PORT socket-server)
  2772.  
  2773. Returns the port which was bound using SOCKET-SERVER.
  2774.  
  2775. (SOCKET-WAIT socket-server [seconds [microseconds]])
  2776.  
  2777. Given time argument(s), waits for (possibly zero) fixed duration for a connect
  2778. on the socket-server.  Without an argument, SOCKET-WAIT blocks indefinitely.
  2779.  
  2780. (SOCKET-ACCEPT socket-server)
  2781.  
  2782. Creates the server-side two-way stream for the connection.
  2783.  
  2784. (SOCKET-CONNECT port [host])
  2785.  
  2786. Attempts to create a client-side two-way stream.  Blocks until
  2787. the server accepts the connections.
  2788.  
  2789. (SOCKET-STREAM-HOST socket-stream)
  2790. (SOCKET-STREAM-PORT socket-stream)
  2791.  
  2792. These two functions return information about the 
  2793. socket stream.  For a server, SOCKET-STREAM-HOST
  2794. returns NIL.
  2795.  
  2796. (SOCKET-SERVICE-PORT "service-name")
  2797.  
  2798. A convenience function for looking up a port given the service name.
  2799.  
  2800. (SOCKET-STREAM-PEER-HOST socket-stream)
  2801.  
  2802. Given a stream, this function returns the name
  2803. of the host on the opposite side of the connection;
  2804. the server-side can use this to see who connected.
  2805.  
  2806.  
  2807. Authors:
  2808. --------
  2809.  
  2810.         Bruno Haible                    Michael Stoll
  2811.         Augartenstra▀e 40               Gallierweg 39
  2812.     D - 76137 Karlsruhe             D - 53117 Bonn
  2813.         Germany                         Germany
  2814.  
  2815. Maintainer:  marcus@sysc.pdx.edu
  2816.              haible@ma2s2.mathematik.uni-karlsruhe.de
  2817.